简体   繁体   English

如何在单击按钮之前隐藏jlist?

[英]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. 我是初学程序员,为演示文稿编写一个简单的jApplet。 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. 我还试图将可见的行数设置为0.这并没有完全摆脱它,但它足以满足我的意图。 When I try to change that in the btnclick function to 当我尝试在btnclick函数中将其更改为

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. 应该注意的是,它位于JScrollPane(feelingSPnl)中,即使我不想要它,netbeans也会继续添加。

JList (and actually every other Swing component) has a setVisible() method that it inherits for JComponent. JList(实际上是每个其他Swing组件)都有一个为JComponent继承的setVisible()方法。 See the Javadoc . 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. 设置Jlist的JScrollPane可见(false),然后在actionPerformed中将其设置为可见(true)以显示相应的按钮。 Note that, if you only set to invisible the list, you'll get the empty scrollpane. 请注意,如果您只设置为隐藏列表,您将获得空滚动窗格。

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

相关问题 在jPanel中单击jButton后,如何隐藏它 - How do I hide a jButton after it has been clicked in a jPanel 如何使Java程序暂停直到按下特定按钮? - How can I make my Java program pause until a specific button has been pressed? 在JList中选择项目后,我将如何编码? - How would I code when a item has been selected in a JList? 如果拖动或单击组件,我该如何区别? - How can I difference if a component has been dragged or clicked? Java:如何显示Hello World! 单击按钮后 - Java: How to show Hello World! after button has been clicked 在JavaFx中单击按钮后如何更改变量 - How to change a variable when a button has been clicked in JavaFx 如何使用actionPerformed()检查是否已单击按钮? - How to use actionPerformed() to check to see if a button has been clicked? 我如何等待,直到RabbitMQ消息已同步到集群中的其他节点? - How can i wait until a RabbitMQ message has been synced to the other nodes in the cluster? 如何以操纵方式重复文本,并重复此操作直到达到我的目标? - How can I repeat text in a manipulative way, and repeat this action until my target has been reached? Selenium [Java]:如何让它等到表被刷新? - Selenium [Java] : How can I make it wait until a table has been refreshed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM