• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing component inside a JScrollPane

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a JScrollPane with the Horizontal ScrollBar set to come on as needed.

I want to be able to remove the component (JPanel) added to scrollpane, and then add a different one (say a larger one),
and have the scrollbar update itself so I can then view all of the new component, but I'm not sure how to do it other than perhaps just rebuilding a new ScrollPane, and I guess I'll have to add this into the JPanel its in again too.

Any thoughts? Thanks
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JScrollPane.setViewportView for changing the component, then call revalidate() and repaint() to enforce that the scroll bars are reset correctly.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I got it to work using:



I'm not sure if thats what you meant.

It also appears to work using either of setViewPortView or revalidate, so I'm not sure.
I guess I'll stick with what I've got above.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's exactly what I meant. revalidate() and repaint() may not be needed, but sometimes you do need them when you modify your user interface at runtime so I always add them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic