PDA

View Full Version : Java JList(NetBeans)


Blade_runner
03-08-2007, 07:51 AM
Hi

Could someone help,i have a TextArea that a user enter text then submits the text to the database, i have a jlist that retrieves the text and displays it. the proble is the list does not update immediately i have tried repainting the list but it seems not to work.


the Jlist code on post-creation

//code
listModelMsg = new DefaultListModel();

String msgList = "SELECT msg_text FROM msg_board ORDER BY msg_id ASC";

try
{
this.resultSet = this.connection.executeQuery(msgList);

while(this.resultSet.next())
{
listModelMsg.addElement(this.resultSet.getString("msg_text"));

}
jList12.repaint();
jList12.setModel(listModelMsg);
}

catch(SQLException e)
{
e.printStackTrace(System.err);
}

Any help is welcome.

Aradon
03-08-2007, 06:04 PM
I'll be honest that I find that when I was doing heavy GUI work in my undergrad I came up with this problem frequently.

And to be honest I can't remember how I fixed it, however I did find a helpful link on how repaint works:

repaint (http://mindprod.com/jgloss/repaint.html)

My only suggestion is to try and add validate() before the repaint. Or put an int parameter in there. Besides that I'm unsure and if there is a more stable solution I'd like to hear it as well.

Blade_runner
03-12-2007, 11:42 AM
Thanks Aradon, i will let you know when i get it right.

Gox
03-12-2007, 01:10 PM
I'll admit my Java GUI skills are lacking. I'll take a (possibly stupid) shot in the dark.

Do you notice any change if you reorder,
jList12.repaint();
jList12.setModel(listModelMsg);

TO
jList12.setModel(listModelMsg);
jList12.repaint();

I only suggest it since it seems to make sense to always repaint as the last step. However, in some cases of course it doesn't matter.

Let us know your solution.
Gox