简体   繁体   English

在“提交”按钮上单击生成一个jlist

[英]generate a jlist on a “submit” button click

I am developing a java desktop application using netbeans. 我正在使用netbeans开发Java桌面应用程序。 I have a panel to which I want to add a jlist whose items and values have to be added dynamically. 我有一个面板,我要向其中添加一个jlist,其项目和值必须动态添加。 Also, I want this Jlist to be created after hitting a "submit" button on the page. 另外,我希望在单击页面上的“提交”按钮后创建此Jlist。 How do I achieve this ? 我该如何实现? I tried adding an action to the button and writing the code there. 我尝试将操作添加到按钮并在其中编写代码。 But, it is not generating any list. 但是,它不会生成任何列表。

Any help in this regard would be appreciated. 在这方面的任何帮助将不胜感激。 Thanks. 谢谢。

Whenever you add components to a visible GUI the basic code is: 只要将组件添加到可见的GUI,基本代码就是:

JList list = new JList(...);
panel.add( list );
panel.revalidate();
panel.repaint();

If your GUI was designed using the IDE then it probably uses GroupLayout, in which case the code is far more complex because you need to specify the GroupLayout constraints when you add the component. 如果您的GUI是使用IDE设计的,则它可能使用GroupLayout,在这种情况下,代码要复杂得多,因为添加组件时需要指定GroupLayout约束。 In this case my advice is to dump the GUI designer and do the GUI layout yourself by using the appropriate combination of layout managers. 在这种情况下,我的建议是转储GUI设计器,并通过使用布局管理器的适当组合自己进行GUI布局。

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

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