Working with JTable in IntelliJ IDEA


I created a jtable in a gui form in intellij and I don't see any data. The strangest thing is that when I use it without creating a form in intellij, the code works.
I used the most common example
String[] columnNames = {"First Name", "Last Name"};
Object[][] data = {{"Kathy", "Smith"},{"John", "Doe"}
and then JTable table = new JTable(data, columnNames);
But I do not get any data.
Is it because of the layout manager?
any help in continuing to work with intellij gui and jtable?
any good jtable + gui intellij example?

+4
source share
2 answers

IDEA GUI Designer JTable , new JTable(...) , IDEA, , Designer, .

, 2 . - IDEA , table.setModel(dataModel); dataModel.

, JScrollPane scrollPane.setViewportView(myTable); ,

IDEA , Custom Create. JTable , IDEA createUIComponents() , , ... = new JTable(...).

.

+11

IntelliJ :

package swing;

import javax.swing.*;

/**
 * JTableTest
 * User: Michael
 * Date: 11/7/10
 * Time: 4:49 PM
 */
public class JTableTest
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("JTable Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTable table = createTable();
        JScrollPane scrollPane = new JScrollPane(table);
        frame.getContentPane().add(scrollPane);
        frame.pack();
        frame.setVisible(true);
    }

    public static JTable createTable()
    {
        String[] columnNames = {"First Name", "Last Name"};
        Object[][] data = {{"Kathy", "Smith"},{"John", "Doe"}};
        JTable table = new JTable(data, columnNames);
        table.setFillsViewportHeight(true);

        return table;
    }
}
+1

Source: https://habr.com/ru/post/1773542/


All Articles