对话框代码:
d1=new JDialog(this,"Help Menu",true);
// Set size
d1.setSize(500,180);
// Set some layout
d1.setLayout(new FlowLayout());
d1.add(new JLabel("<html>Thank you for using the poster ordering system. <br> To begin, please select your desired poster size using the option menu provided. <br> Next, choose your desired poster style. <br> Now you can choose your quantity and background colour for your poster. <br> you are now finished! Your price will be displayed at the bottom right of the screen. <br> The pricing will show prices with and without VAT for your convenience.<br></html>"));
JButton button = new JButton("close");
d1.setVisible(true);
button.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
});
它表示在解析之前已到达文件末尾,并且不会在帮助对话框上显示“关闭”按钮。当我添加“JButton.setVisible(true);”时它说:“不能从静态上下文引用非静态方法 setVisible(boolean)”
如有任何建议,我们将不胜感激。 我是 Java 新手,这让我很困惑!
最佳答案
替换以下代码:
JButton button = new JButton("close");
用这个:
static JButton button = new JButton("close");
关于java - Netbeans:JButton 按钮无法设置可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30104247/