swing - List box does not show up using java in netbeans -


I have the following code that is executed when a button is pressed. I have used the GUI builder inside NetBeans for the rest of the GTI.

  Private zero-populated BTN effect (Java.av.te.Event.Event EventEVT) {String Query = "Do not Access Accounts"; Try {connect.rs = connect.st.executeQuery (query); Of vector & lt; String & gt; Temp = new vector & lt; String & gt; (); While connect (rs.next ()) {temp.add (connect rs.getString ("AccNo")); } JLICL accList = new jlit; JPanel4.add (accList, BorderLayout.CENTER); } Hold (exception e) {JOptionPane.showMessageDialog (null, e); }}  

Why the list box does not show?

What am I doing?

Why not show the list box? What am i doing wrong

For this reason:

  jlICr accList = new jlit; JPanel4.add (accList, BorderLayout.CENTER);  

These lines show that when you are trying to add JList by clicking on a button, then jPanel4 already Has been displayed, and thus you will have to modify the panel again and again by doing this:

  jPanel4.add (accList, BorderLayout.CENTER); JPanel4.revalidate (); JPanel4.repaint ();  

However, when we can combine the components dynamically in the swing, we give place to all our components before the top-level containers appear.

See the tutorial.

In this case you should split the list into your components (do not forget the scroll panel) and should update its model.

Other notes

Keep in mind that database calls are time-consuming tasks and the GUI may stop becoming unresponsive. EDT is a single and special thread where swing components are created and updated. To avoid blocking this thread, use the database call in the background thread and to update swing components in EDT. See more in lesson.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -