Skip to main content

JSplitPane Auto Divider Location

3 replies [Last post]
scidocks
Offline
Joined: 2003-06-12

I'm using a JSplitPane with a HORIZONTAL_SPLIT.
The component to the right of the divider has a dynamic size - I'm actually using a CardPanel. When a new JPanel
is added to the right side, and whose size is bigger than
the current JPanel on that side, I would like the divider
to move LEFT (just enough) so that the new JPanel would
be fully visible. Can someone give me a tip on how to
achieve this ?

TIA

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kwalrath
Offline
Joined: 2006-02-17

Have you tried invoking resetToPreferredSizes()
on the split pane after adding the new panel?

-k-

scidocks
Offline
Joined: 2003-06-12

> Have you tried invoking resetToPreferredSizes()
> on the split pane after adding the new panel?

> -k-

That worked perfectly....Muchos Gracias

The funny thing is that I was indeed invoking that method
at compile time - that is, when the very first JPanel
was being added to the right side. At run time, however,
in the class that I was modifying the right side component, I didn't have access to its container - the JSplitPane. So, I was trying something like revalidate()
on the right side component to see if the message would
propagate up the hierarchy.

Anyways, much thanks for the help.

kwalrath
Offline
Joined: 2006-02-17

You're welcome! I recently worked on the tutorial's split pane sizing section, so it was fresh in my mind. The new section will go online when we update the whole tutorial, which should be by the beginning of next week.

-k-
http://java.sun.com/docs/books/tutorial/