Frage

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.

Assuming that i have 2 JLabels named Label1 and Label2

The idea in my mind would be to go for the constructor of the JFrame class and write

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

Then at the ActionPerformed function of the Submit button

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?

War es hilfreich?

Lösung

make sure that you put

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

after the initComponents(); method call! for example if your JFrame name is: NewJFrame you should change constructor with this code:

public NewJFrame() {

        initComponents();

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

Andere Tipps

Have you tried typing Label1.setVisible(true); for example? (Notice the ';' mark)

Or check what errors comes up and post it here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top