简体   繁体   中英

How can i display the JTable?

I created a JTable in a JScrollPane , but its not showing in the program.

Here is my code:

        scrollPaneTable = new JScrollPane();
        scrollPaneTable.setBounds(10, 507, 854, -480);
        
        table = new JTable();
        table.setForeground(Color.BLACK);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        table.setCellSelectionEnabled(true);
        table.setFillsViewportHeight(true);
        table.setBackground(Color.LIGHT_GRAY);
        table.setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.GRAY, null));
        table.setModel(new DefaultTableModel(
            new Object[][] {
                {"PC", "Computer", "Dominik", "Test", "Test"},
            },
            new String[] {
                "Name", "Beschreibung", "Nutzer", "Ort", "Seriennummer"
            }
        ));
        table.setColumnSelectionAllowed(true);
        table.setVisible(true);
        scrollPaneTable.setViewportView(table);
        jFW.getContentPane().add(scrollPaneTable);

You don't have a main method, you initialize UI and create JTable etc. in the Constructor of Gui class.

You need to create new Gui object in main to see Frame Table etc. (Not neccesarily inside the Gui class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM