JTable不从Window Builder Eclipse显示

时间:2013-02-08 18:24:56

标签: eclipse jframe jtable

我刚刚开始使用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,所以它可能很简单,但我无法弄明白。

1 个答案:

答案 0 :(得分:0)

对不起问题是这条线,“     contentPane.setLayout(null);“不知道它是怎么到达的。至少它的工作啊!”