---
title: "JTable"
type: "forum-thread"
url: "https://www.webforum.nu/amne/java/168756-jtable"
topic: "Java"
topic_url: "https://www.webforum.nu/amne/java"
author: "Asa"
published: "2008-02-05T18:55:28.000Z"
updated: "2008-02-06T14:46:08.000Z"
replies: 1
views: 491
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/java/168756-jtable"
---

# JTable

## #1 — Asa, 2008-02-05T18:55Z

Har jag gjort fel? Den skall via en JMenu anropa denna funktionen i min lyssnare och öppna det i en ny ruta. Alltså det som ska visas är en JTable i en JFrame.

```
    private JPanel getFileListPanel()
    {
        fileListPanel = new JPanel();
        fileListPanel.setName("Visa allt i en tabell");
        fileListPanel.setLayout(new BorderLayout());
        fileListPanel.setBorder(new EtchedBorder());
    
        String[] columnNames = { "Path","File Name","File Size" };
        Object[][] rowData = {
            { "a","b","c" }
            ,
            { "d","e","f" }
        };
    
        fileList = new JTable(rowData, columnNames);
        fileList.setName("Visa allt i en tabell");
        fileListPanel.add(fileList, BorderLayout.CENTER);
    
        return fileListPanel;
    }
```

Permalänk: https://www.webforum.nu/p/168756

## #2 — Asa, 2008-02-06T14:46Z

Jag gjorde så här:

```
    private void getFileListPanel()
    {
        JFrame tabell = new JFrame("Visa bilarna i tabell");
        //tabell.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fileListPanel = new JPanel();
        fileListPanel.setName("Visa allt i en tabell");
        fileListPanel.setLayout(new BorderLayout());
        fileListPanel.setBorder(new EtchedBorder());
    
        String[] columnNames = { "Regnr","Märke","Modell","Årsmodell","BildURL" };
        Object[][] rowData = new Object[bilDB.antalBilar()][columnNames.length];
        for(int i = 0; i<bilDB.antalBilar(); i++){
            Bil c = bilDB.getBil(i);
            for (int j = 0; j<c.getBilar().length; j++){
                rowData[i][j] = c.getBilar()[j];
            }
        }
        
        fileList = new JTable(rowData, columnNames);
        fileList.setName("Visa allt i en tabell");
        fileListPanel.add(fileList);
        tabell.getContentPane().add(fileListPanel);
        tabell.setLocation(300, 150);
        tabell.pack();
        tabell.setVisible(true);
    }
```

Sen anropar jag den med denna i samma fil:

```
getFileListPanel();
```

Permalänk: https://www.webforum.nu/p/2077929

---

Tråden på webben: https://www.webforum.nu/amne/java/168756-jtable
