Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Updating the DefaultListModel and "repainting" the JList...

879 views
Skip to first unread message

Lisa

unread,
Jul 11, 2001, 1:19:46 PM7/11/01
to
I currently have a JFrame that has a JList.

I declare the JList in the following fashion:
constructListModel _idListModel = new constructListModel();
JList _idList = new JList(_idListModel);

The constructListModel actually is just the following:
public class constructListModel extends DefaultListModel{

public constructListModel(){
super();
}
public void rowChanged(int start, int end){
fireContentsChanged(this,start,end);
}
}

Now when I create the JFrame, we basically want to display the window
first while creating a separate thread to retrieve information from
the Database and inserting the result set into a constructListModel.
When this thread returns as finished, the JLIst should "refresh" now
displaying the retrieved records.

see that the count of the list model is correct in "rowChanged"
however, the display does not show all the records retrieved. The
JList display is still blank. I have tried "repaint", "revalidate",
etc. and it still does not work.

Any suggestions?

Thanks.
Lisa

Christian Kaufhold

unread,
Jul 11, 2001, 5:34:33 PM7/11/01
to
Lisa <lch...@telcordia.com> wrote:

> The constructListModel actually is just the following:
> public class constructListModel extends DefaultListModel{

> public constructListModel(){
> super();
> }
> public void rowChanged(int start, int end){
> fireContentsChanged(this,start,end);
> }
> }

> Now when I create the JFrame, we basically want to display the window
> first while creating a separate thread to retrieve information from
> the Database and inserting the result set into a constructListModel.
> When this thread returns as finished, the JLIst should "refresh" now
> displaying the retrieved records.

> see that the count of the list model is correct in "rowChanged"
> however, the display does not show all the records retrieved. The
> JList display is still blank. I have tried "repaint", "revalidate",
> etc. and it still does not work.


Please post more code.


Christian

Laurent Garnier

unread,
Jul 12, 2001, 3:39:06 AM7/12/01
to
Classic update in another thread than AWT ?
If so, try SwingUtilities.invokeLater.

Lisa a écrit :

Lisa

unread,
Jul 12, 2001, 11:06:38 AM7/12/01
to
The code is situated in the following fashion:

public class MyDialog extends JFrame {
.
.
.
.
//private vars.
private JList _idList = new JList();
private constructListModel _model;

public MyDialog(){
super();
addWindowListener(new WindowAdapter(){
public void windowActivated(WindowEvent e){
//code here for initial focus of window
}
});

initComponents();
setData();
}

private initComponents(){

this.setSize(...);
//blah blah blah setting up layouts, etc.

}

.
.
.
public void setData(String [] args){

.
.
.
this.setVisible(true);
//we want to show the window first, busy it out (i.e. show the
//busy cursor icon on the mouse pointer) while the new
//thread is busy getting stuff from the database.

final constructDataThread dbthread = new constructDataThread();
dbthread.start();
}

private class constructDataThread extends Thread{

public void run(){
doConstructData();
}
public void doConstructData(){
//all the work to get at least 90,000 rows from the db into a
//DefaultListModel to save time of iterating through a vector
// to put into the list model

SwingUtilities.invokeLater(new Runnable(){
public void run(){
doFinished();
}
});
}
public void doFinished(){
if(list model is null or size is zero)
return;
else{
_idList.setModel(_model);
_idList.revalidate();
_idList.repaint();
}
}
}

class constructListModel extends DefaultListModel{

public constructListModel(){
super();
}
public void rowChanged(int start, int end){
fireContentsChanged(this,start,end);
}
}

}


The JList never refreshes w/ the new data retrieved in the separate thread.

Please advise.
Thank you.

Lisa

Laurent Garnier <lgar...@genigraph.fr> wrote in message news:<3B4D53E6...@free.fr>...

Christian Kaufhold

unread,
Jul 13, 2001, 11:48:43 AM7/13/01
to
Lisa <lch...@telcordia.com> wrote:

[...]

> public void doConstructData(){
> //all the work to get at least 90,000 rows from the db into a
> //DefaultListModel to save time of iterating through a vector
> // to put into the list model

> SwingUtilities.invokeLater(new Runnable(){
> public void run(){
> doFinished();
> }
> });
> }
> public void doFinished(){
> if(list model is null or size is zero)
> return;
> else{
> _idList.setModel(_model);

That doesn't make sense. The _model is already set on the list.

Where and how are you actually changing the model? Or does doConstruct-
Data create a new one?

> _idList.revalidate();
> _idList.repaint();

That is done automatically.

Christian

Lisa

unread,
Jul 24, 2001, 3:14:23 PM7/24/01
to
use...@chka.de (Christian Kaufhold) wrote in message news:<3t3b4f18...@simia.chka.de>...

The DefaultListModel is returned by another class that acts as a
database manager. A method "getIds()" returns DefaultListModel to this
JFrame class....so it's merely a copy and then the JFrame class will
try to set this copy as the DefaultListModel for its JList.

Lisa

Christian Kaufhold

unread,
Jul 25, 2001, 11:59:17 AM7/25/01
to
Lisa <lch...@telcordia.com> wrote:

[...]

> The DefaultListModel is returned by another class that acts as a
> database manager. A method "getIds()" returns DefaultListModel to this
> JFrame class....so it's merely a copy and then the JFrame class will
> try to set this copy as the DefaultListModel for its JList.

I don't really understand everything anymore.

How many different list models are involved?

Check the JLists involved whether they have the ListModel you assume
they have.

Avoid creating multiple list models if that may cause confusion about
which one is meant.


Christian

0 new messages