java - Netbeans:JButton 按钮无法设置可见

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

最佳答案

替换以下代码:

JButton button = new JButton("close");

用这个:

static JButton button = new JButton("close");

关于java - Netbeans:JButton 按钮无法设置可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30104247/

相关文章:

Java 在根路径上设置 cookie

java - 线程安全、静态方法和一些奇怪的代码

java - netbeans 有类似 Eclipse 调试显示 View 的东西吗

c++ - 演示程序错误 : '' was not declared in this scope

java - 如何在 Spring Data JPA @Modifying @Query 查询中更新 JPA/Hibernate @Version 字段?

java - 这是处理整数最快的结构(添加,从数千个节点读取)

java - Gson - 无法解析的日期错误?

java - Tomcat 无法在主机上下文 server.xml 中设置 'source' 属性集

java - 为 Netbeans java 项目创建安装文件

php - 如何让 Netbeans PHPUnit 代码覆盖率在 Windows 上运行?