• 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

JSplitPane resizing

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSplitPane where the top component has a JPanel in it that has components on it that are set visible depending on if the user checks a box or not. Initially these components' visiblity are set to false. When the user checks the box to make these components visible, the divider stays in the same place until the user takes action to move it. How can I get the divider to automatically move up or down when the user is making the components visible/invisible?
Thanks!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to call validate()/invalidate() on the component that holds the split pane so that the layout manager takes the newly visible components into account.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I tried calling validate()/invalidate() on the component that is holding my JSplitPane, and it didn't seem to make a difference. I called validate() if the box was checked, and invalidate() if the box was unchecked.
Is that right, or do I need to be doing something different?
Thanks!
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jennifer
i guess you need to call validate() on the both the situations.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried calling validate on both of the situations, and that still did not work.
Any other ideas?
Here's what I am doing:
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it to work by calling invalidate() and validate() on the component that is changing, and then by calling resetToPreferredSizes() on the splitpane.

Here's my test code...

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to add the code to my program to resize the split pane, and it worked. The only problem I have, is it's resizing it backwards. When the app first comes up the check box is not selected. When I do select it, the split Pane does nothing. However, when I deselect it, the splitPane resizes to allow for the components that aren't there.
Here's my code:

Any ideas?
Thanks again!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show where in the code the components get hidden/shown? This should be based off the state of the checkbox (or the checkbox should be based off the isVisible() results...) and it should be before this segment of the code...
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all of your help. I think I've finally got it. I looked at my code again after your last response and found that the method that disabled/enabled my components was not running first. I changed it, and now it works beautifully!
Thanks for the help, I really appreciate it !!
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nate,
Inside

I have commented invalidate() and validate() out and still it works fine.
Q: What is the use of using invalidate and validate in this situation.
Thank you
Garandi
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops! I originally tried the invalidate()/validate() and it changed the size of the component, but did not change the splitpane. So I looked in JSplitPane and found resetToPreferredSizes(). resetPreferredSizes() probably calls some validation, so you are right, the invalidate()/validate() before is not needed. I just didn't check to see if invalidate()/validate() were still needed after adding resetPreferredSizes().
reply
    Bookmark Topic Watch Topic
  • New Topic