Netbeans:JButton Button无法设置可见

时间:2015-05-07 14:37:21

标签: java netbeans

对话代码:

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的新手,这让我很困惑!

2 个答案:

答案 0 :(得分:1)

替换以下代码:

UIViewController

这一个:

JButton button = new JButton("close");

答案 1 :(得分:0)

您没有将按钮添加到JDialog:

d1.add(button);