Chilam February 2016

Netbeans Jlabel visibility when switching tabs

I'm working on a jframe program where I have 2 tabs (Home & About) .. now I would like to display a jlabel in the about tab only when a button is clicked , I managed to do that by using jLabel5.setVisible(true); ... it works fine , but when I go back to the home tab and go back again to the about tab , the jlabel is gone so I have to press again so it can appear ... is there a way that I can make it stay there without it resetting everytime i switch tabs? thanks ... this is a gif showing what exactly my problem is http://imgur.com/LEaYQxL

Answers


Gabriel Mendez February 2016

Perhaps you could share the code, however there might be a work around, you could try to create a "flag" which is only a variable that is going to be true or false, create a variable flag that will change to true once you click in your button and then, when you pass to the About tab you will check if flag is true then jLabel5.setVisible(true) else jLabel5.setVisible(false), remember to initialize the flag variable as false.

Hope this work around works for you


Simone C. February 2016

You could try to make this: when you click the button you set the setVisible(true) and also set "true" a false boolean. So you click, the boolean wasClicked, that was false became true, and before you write if wasClicked is true: setVisible(true). A code example:

boolean wasClicked = false;

if(wasClicked == true) {
jLabel5.setVisible(true);
}

When button is clicked (actionlistener):

wasClicked = true;
jLabel5.setVisible(true);

Post Status

Asked in February 2016
Viewed 1,318 times
Voted 7
Answered 2 times

Search




Leave an answer