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 / August 2005

Tip: Looking for answers? Try searching our database.

JScrollPane reassigning contents...

Thread view: 
6e - 31 Aug 2005 17:22 GMT
Hi thanks for reading,

Im using a JScrollPane to hold a JTable.  Im able to assign the Table
to the JScrollPane without any difficulties, however I have 3+ JTables
that I would like to swap in and out of the JScrollPane.

The number of JTables needed to be swaped is variable.  When I try the
code below, it causes the first table shown to act as if frozen,
without even allowing me to select a row.

My code consists of:

spTable= new JScrollPane(table);
spTable.removeAll();
spTable.validate();
spTable.add(myTable);
spTable.validate();

I also tried revalidate, but it still doesn't seem to change anything.
It seems like a simple problem, but I cant figure it out...
Thomas Fritsch - 31 Aug 2005 17:45 GMT
> Hi thanks for reading,
>
[quoted text clipped - 10 lines]
> spTable= new JScrollPane(table);
> spTable.removeAll();
This removes the scrollpane's JViewport and JScrollBars. Don't do this!

> spTable.validate();
> spTable.add(myTable);
This adds directly to the scrollpane, not to its JViewport. Don't do!
Instead do:
  spTable.setViewportView(myTable);

> spTable.validate();
>
> I also tried revalidate, but it still doesn't seem to change anything.
> It seems like a simple problem, but I cant figure it out...
The validate() calls should not be needed anymore.

See the javadoc of JScrollPane#setViewportView. Quoted from there:
"Applications should not add children directly to the scrollpane."

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

6e - 31 Aug 2005 17:48 GMT
Thanks, it worked wonders.


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.