Moahammad mehdi
Moahammad mehdi

Reputation: 113

how can i see my table in gridlayout?

It's a part of my project that is related to my artificial intelligence course in my university.For doing that i want to create an application that takes two values as inputs. The inputs has to enter into to my two tables by user.So for getting two inputs I insert my tables in gui but when i ran this code i couldn't see my noted gui(I mean my two tables) .here's my code:

public class UserInterface extends JFrame {

private JTable table1;
private JTable table2;
private String[] ColumnName = { "", "", "", "" };
private Object[][] content = {{"1","2","3","4"},{"5","6","7","8"},{"9","10","11","12"},{"13","14","15","16"}};
private DefaultTableModel tableModel;
private JPanel columnPanel;
private JPanel buttonpanel;
private JButton BFS = new JButton("BfS Search");
private JButton IDS = new JButton("IDS Search");
private JButton ASTAR = new JButton("A* Search");
private JButton BIdirect = new JButton("Bidirectional Search");

public UserInterface() {

    getContentPane().setLayout(
            new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    setSize(new Dimension(400, 500));
    GridLayout gridLayout = new GridLayout(1, 2);
    tableModel = new DefaultTableModel(content, ColumnName);
    table1 = new JTable(tableModel) {
        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    table2 = new JTable(tableModel) {
        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    gridLayout.addLayoutComponent("Table1", table1);
    gridLayout.addLayoutComponent("Table2", table2);
    columnPanel = new JPanel();
    columnPanel.setLayout(gridLayout);
    add(columnPanel);
    buttonpanel = new JPanel();
    buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.X_AXIS));
    buttonpanel.add(BFS);
    buttonpanel.add(IDS);
    buttonpanel.add(ASTAR);
    buttonpanel.add(BIdirect);
    add(buttonpanel);
    Tools.setCenterLocation(this);
    Tools.setTheme(this);
}

public static void main(String[] args) {
    UserInterface interface1 = new UserInterface();
    interface1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    interface1.pack();
    interface1.setVisible(true);
}

}

how can i fix that?

Upvotes: 0

Views: 1028

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

Don't call Layout#addLayoutComponent, it's not your responsibility to call this method, use Container#add instead

columnPanel.add(table1);
columnPanel.add(table2);

Upvotes: 3

Related Questions