简体   繁体   中英

How can I hide a jlist until a button has been clicked?

I am a beginner programmer and writing a simple jApplet for a presentation. The applet asks for the user's name and then says hello to them and asks how they are doing. At that time I want a list of options to appear for the user to select.

The problem is that I do not know how to hide the list. I have looked through the properties and couldn't find a display or visible option. I have also tried to set the visible row count to 0. Which doesn't get rid of it completely but it is good enough for my intentions. When I try to change that in the btnclick function to

feelingLst.setVisibleRowCount(4);

Nothing shows up.

How can I hide this box and then show it when I need it? It should be noted that it is inside a JScrollPane (feelingSPnl) which netbeans keeps adding even though I do not want it.

JList (and actually every other Swing component) has a setVisible() method that it inherits for JComponent. See the Javadoc .

So you can write:

feelingList.setVisible(false);

Set visible(false) the JScrollPane of the Jlist, and then set it back to visible(true) in the actionPerformed for the corresponding button. Note that, if you only set to invisible the list, you'll get the empty scrollpane.

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