简体   繁体   English

我如何在gridlayout中看到我的桌子?

[英]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: 输入必须由用户输入到我的两个表中。因此为了获得两个输入,我将表插入gui中,但是当我运行此代码时,我看不到我提到的gui(我的意思是我的两个表)。这是我的代码:

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? 我该如何解决?

Don't call Layout#addLayoutComponent , it's not your responsibility to call this method, use Container#add instead 不要调用Layout#addLayoutComponent ,调用此方法不是您的责任,请改用Container#add

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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