JList and DefaultListModle used w/ separate threads for performance


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JList and DefaultListModle used w/ separate threads for performance

Hybrid View

  1. #1
    Lisa Guest

    JList and DefaultListModle used w/ separate threads for performance


    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

    Post a follow-up to this message

    Message 2 in thread
    From: Christian Kaufhold (usenet@chka.de)
    Subject: Re: Updating the DefaultListModel and "repainting" the JList...

    Newsgroups: comp.lang.java.gui
    Date: 2001-07-11 14:39:46 PST



    Lisa <lcheng1@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

    Post a follow-up to this message

    Message 3 in thread
    From: Laurent Garnier (lgarnier@genigraph.fr)
    Subject: Re: Updating the DefaultListModel and "repainting" the JList...

    Newsgroups: comp.lang.java.gui
    Date: 2001-07-12 00:39:06 PST



    Classic update in another thread than AWT ?
    If so, try SwingUtilities.invokeLater.

    Lisa a écrit :
    >
    > 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


    Post a follow-up to this message

    Message 4 in thread
    From: Lisa (lcheng1@telcordia.com)
    Subject: Re: Updating the DefaultListModel and "repainting" the JList...

    Newsgroups: comp.lang.java.gui
    Date: 2001-07-12 08:06:50 PST



    The code is situated in the following fashion:

    public class MyDialog extends JFrame {

  2. #2
    Paul Clapham Guest

    Re: JList and DefaultListModle used w/ separate threads for performance

    Swing itself runs in a separate thread. So if you want Swing to display
    something later, you have to tell it to do so by using code something like
    this:

    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    fillTheList(); // put code here that fills up your JList
    }
    });

    You don't need to put this in a separate Thread, it will run in the Swing
    thread. However Swing will update the display when you first create your
    frame and then again after it executes this code.

    PC2

    "Lisa" <lcheng1@telcordia.com> wrote in message
    news:3b4e068b$1@news.devx.com...
    >
    > 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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center