Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

JList doesn't constantly refresh

Thread view: 
ravxm - 05 Dec 2006 07:42 GMT
I'm having a problem updating my jLists. I'm trying to update it using
the jList.setListData(array) while in a loop so that it's constantly
updated. Any suggestions or strategies are greatly appreciated. Thanks

private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
       int number2=4;
       double arrivalrate2=.000003;
       do{
               if(Math.random()<arrivalrate2)
               {
                   Random rand2=new Random();
                   number2=rand2.nextInt(2);
               int lanenumberassigned;
               Auto auto=getAuto();
               LaneStatusRunnable lsrunnable=new
LaneStatusRunnable(lane1queue,lane2queue,lane3queue,lane4queue,lane5queue,lane6queue);
               lanenumberassigned=lsrunnable.getLaneAssignment();
               switch(lanenumberassigned)
               {
                   case 1:
                       lane1queue.add(auto);
                      jList1.setListData(lane1queue.toArray());
                       System.out.println("Lane 1 assigned");
                       break;
                   case 2:
                       lane2queue.add(auto);
                       jList2.setListData(lane2queue.toArray());
                       System.out.println("Lane 2 assigned");
                       break;
                   case 3:
                       lane3queue.add(auto);
                       jList3.setListData(lane3queue.toArray());
                       System.out.println("Lane 3 assigned");
                       break;
                   case 4:
                       lane4queue.add(auto);
                       jList4.setListData(lane4queue.toArray());
                       System.out.println("Lane 4 assigned");
                       break;
                   case 5:
                       lane5queue.add(auto);
                       jList5.setListData(lane5queue.toArray());
                       System.out.println("Lane 5 assigned");
                       break;
                   case 6:
                       lane6queue.add(auto);
                       jList6.setListData(lane6queue.toArray());
                       System.out.println("Lane 6 assigned");
                       break;

                   default:
                       System.out.println("Error at lanenumberassigned
switch");
                       break;

               }
               }
       }while(number2!=5);
}
Andrew Thompson - 05 Dec 2006 08:42 GMT
> I'm having a problem updating my jLists. I'm trying to update it using
> the jList.setListData(array) while in a loop so that it's constantly
> updated.

The code is probably blocking the EDT.

> Any suggestions or strategies are greatly appreciated.

Don't (block the EDT).  

Andrew T.
ravxm - 05 Dec 2006 12:54 GMT
would it work as a timer fired event every few seconds??
Thomas Hawtin - 05 Dec 2006 17:04 GMT
> would it work as a timer fired event every few seconds??

Probably. Use javax.swing.Timer not java.util.Timer.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.