JTable不从Window Builder Eclipse显示

问题描述 投票:1回答:1

我刚刚开始使用Eclipse Window Builder插件为我的程序创建一个JFrame,但是当添加一个JTable时它就没有显示出来。该程序就像它在那里,但不会显示它。

public class Stock extends JFrame {

private static final long serialVersionUID = -4904110593143929972L;
private JPanel contentPane;
private JTable table;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Stock frame = new Stock();
                frame.setVisible(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Stock() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnNewMenu = new JMenu("Add");
    menuBar.add(mnNewMenu);

    JMenu mnNewMenu_1 = new JMenu("Delete");
    menuBar.add(mnNewMenu_1);

    JMenu mnNewMenu_2 = new JMenu("Edit");
    menuBar.add(mnNewMenu_2);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    table = new JTable();
    table.setBounds(10, 230, 414, -221);
    contentPane.add(table);

    loadTable();
}

public void loadTable() {
    String[] columnNames = {"Key",
            "Name",
            "Quantity",
            "Price per unit"};

    Object[][] data = {
            {"1","Name","10","�2.40"}};

    table = new JTable(data, columnNames);
    contentPane.add(table);
}

}

就像我说的那样,我刚开始使用Window Builder,所以它可能很简单,但我无法弄明白。

eclipse jframe jtable
1个回答
0
投票

对不起,问题是这一行,“contentPane.setLayout(null);”不知道它是如何到达那里的。啊,至少它的工作:)

© www.soinside.com 2019 - 2024. All rights reserved.