我有一个Java的JFrame
类,在其中我想使用一个boxlayout,但是我收到了一个错误提示:java.awt.AWTError: BoxLayout can't be shared
。我看到其他人也遇到了这个问题,但他们通过在contentpane上创建boxlayout来解决它,而这正是我在这里做的事情。这是我的代码:
class EditDialog extends JFrame {
JTextField title = new JTextField();
public editDialog() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("New entity");
getContentPane().setLayout(
new BoxLayout(this, BoxLayout.PAGE_AXIS));
add(title);
pack();
setVisible(true);
}
}