简体   繁体   中英

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

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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