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 / GUI / November 2006

Tip: Looking for answers? Try searching our database.

JScrollPane - ScrollBar - Not Scrolling withJTable

Thread view: 
Bill - 23 Nov 2006 20:05 GMT
Hi All,

   I have a JScrollPane containing a JTable.

   I programatically traverse the JTable by selecting rows and  scrolling
the JTable

           jTable.scrollRectToVisible(r);

   However the scrollbar doesn't get updated until after all my processing
has completed, then the scrollbar 'jumps' to the bottom. Is there any way to
get it to be updated while the jTable is being processed, so the user has
some indication of how far the processing has progressed?

TIA

Bill
Bart Cremers - 24 Nov 2006 11:21 GMT
> Hi All,
>
[quoted text clipped - 13 lines]
>
> Bill

The issue here probably is the fact that Java doesn't get the time to
repaint the scrollpane/table.

To solve this allow remove control from your traverse thread (hopefully
this is a different thread then the event thread) for a short period by
using Thread.yield() or thread.sleep(50).

Regards,

Bart
Bill - 24 Nov 2006 11:40 GMT
Hi Bart,

   I'll give it a try.

Thanks

Bill

>> Hi All,
>>
[quoted text clipped - 27 lines]
>
> Bart
Ian Wilson - 24 Nov 2006 11:51 GMT
>>Hi All,
>>
[quoted text clipped - 20 lines]
> this is a different thread then the event thread) for a short period by
> using Thread.yield() or thread.sleep(50).

I wonder if thread priorities might also be an issue?

On my non-GUI worker threads I use
  t.setPriority(Thread.NORM_PRIORITY);
before invoking
  t.start();.

Just a thought.
Nigel Wade - 27 Nov 2006 10:19 GMT
> Hi All,
>
[quoted text clipped - 13 lines]
>
> Bill

Without seeing your code I can only guess, but you've probably hijacked the EDT
to do your processing. Whilst the EDT is processing your code it can't get on
with what it's supposed to be doing, updating the GUI.

Whatever processing you are doing which calls jTable.scrollRectToVisible(r);
must be done in a thread other than the EDT if you want to see the effects of
that method. Also, note that JComponent.scrollRectToVisible() doesn't say it's
thread safe, so if you want to use it from another thread then you really ought
to wrap that call in a SwingUtilities.invokeLater().

I was going to recommend the section in the Java Tutorial "Creating a GUI with
JFC/Swing", but Sun seem to have re-written this for Java 1.6. The tutorial now
only mentions the use of SwingWorker for creating multiple threads in Swing
(SwingWorker isn't even part of Java 1.5, it's a separate download).

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555



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.