generate a jlist on a "submit" button click
I a开发者_Python百科m developing a java desktop application using netbeans. I have a panel to which I want to add a jlist whose items and values have to be added dynamically. Also, I want this Jlist to be created after hitting a "submit" button on the page. 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:
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. 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.
精彩评论