简体   繁体   English

Java Netbeans Jlabel隐藏和显示

[英]Java Netbeans Jlabel Hide and Show

I have a Jframe form and once this form runs i would like some specfeic labels become invisble until the user press on the "Submit button" they become visible. 我有一个Jframe表单,一旦这个表单运行,我想一些特定的标签变得隐身,直到用户按下“提交按钮”它们变得可见。

Assuming that i have 2 JLabels named Label1 and Label2 假设我有两个名为Label1和Label2的JLabel

The idea in my mind would be to go for the constructor of the JFrame class and write 我的想法是去JFrame类的构造函数并编写

Label1.setVisible(false);
Label2.setVisible(false);

Then at the ActionPerformed function of the Submit button 然后在Submit按钮的ActionPerformed函数中

Label1.setVisible(true);
Label2.setVisible(true);

But this option does not work and netbeans keeps showing several errors, the question is does my idea is not the proper way to do it or i'm just doing it wrong? 但是这个选项不起作用,netbeans不断出现几个错误,问题是我的想法不是正确的方法,或者我只是做错了吗?

make sure that you put 确保你放

Label1.setVisible(false);
Label2.setVisible(false); 

after the initComponents(); initComponents(); method call! 方法调用! for example if your JFrame name is: NewJFrame you should change constructor with this code: 例如,如果您的JFrame名称是:NewJFrame,您应该使用以下代码更改构造函数:

public NewJFrame() {

        initComponents();

        Label1.setVisible(false);
        Label2.setVisible(false);
    }

Have you tried typing Label1.setVisible(true); 你有没有尝试输入Label1.setVisible(true); for example? 例如? (Notice the ';' mark) (注意';'标记)

Or check what errors comes up and post it here. 或者检查出现的错误并在此处发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM