【问题标题】:JTable Not Displaying from Window Builder EclipseJTable 未从 Window Builder Eclipse 中显示
【发布时间】:2013-02-08 18:24:55
【问题描述】:

我刚刚开始使用 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】:

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

    【讨论】:

    • 我设计了故事但看不到标题..你有什么想法吗?
    • 你需要将它包装在一个 JScrollPane 中以使标题可见
    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 2014-08-03
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多