【发布时间】:2014-01-30 19:13:04
【问题描述】:
大家好,我一直使用它作为我的指南和我一直在编写的代码的基础:
我想做的是在所有窗格中添加一个共享按钮。我不想为每个按钮声明一个唯一的按钮,而是一个共享的按钮。我的第一个想法是将框架更改为 boxlayout,然后在将窗格添加到框架后添加一个按钮:
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BoxLayout(frame, BoxLayout.PAGE_AXIS));
//Add content to the window.
//frame.add(new GUI(), BorderLayout.CENTER);
frame.add(new GUI());
//setup Find button
//findButton.setSize(110,55);
findButton.setText("Find");
findButton.setVisible(true);
//add button to frame
frame.add(findButton);
但是,我收到运行时错误:无法共享 BoxLayout。所以现在我在这里结束。在我调查为什么会出现此错误时,有人可以告诉我这是否是正确的方法吗?
【问题讨论】:
标签: java swing jbutton frame jtabbedpane