Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JSplitPane divider location always resets to its initial value

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    858
    Thanks
    0
    Thanked 158 Times in 141 Posts

    Default JSplitPane divider location always resets to its initial value

    Hi.

    I have a JSplitPane in my GUI. Both the left and the right components of this split pane are JScrollPane's.
    The left scroll pane contains a JTree with several items.

    The problem I am having is, that when the user moves the divider location of the split pane, and then selects an item from the JTree on the left, the divider location jumps back into its initial value.
    Annoyed by this behavior I tried to hack it for now with the following code:
    		splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() {
    			public void propertyChange(PropertyChangeEvent e) {
    				scrollPane.setPreferredSize(new Dimension(splitPane.getDividerLocation() - 1, MIN_HEIGHT));
    			}
    		});
    But this hack does not work either. Sometimes it works, but other times when I select an Item the divider location jumps back to the initial value again.
    I am probably overlooking some obvious setting here, but for the love of god I can not find the problem at the moment.

    Thank you all very much.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,104
    My Mood
    Mellow
    Thanks
    244
    Thanked 755 Times in 741 Posts

    Default Re: JSplitPane divider location always resets to its initial value

    Something in your design is ignoring the user's input by resetting the split pane's divider to its original position. Modify your code to preserve the user's input. Review the JSplitPane tutorial and/or post code that demonstrates the problem.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    858
    Thanks
    0
    Thanked 158 Times in 141 Posts

    Default Re: JSplitPane divider location always resets to its initial value

    I think I know now what was the cause of this.
    When certain items within the JTree are selected the rightComponent of the SplitPane is changed. And with changed I mean setRightComponent is being called on the SplitPane.
    So my guess is that this would reset the divider location.

    The solution was simple, before changing the right component I get the old divider location and then set the divider location to its previous value after changing the right component.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,104
    My Mood
    Mellow
    Thanks
    244
    Thanked 755 Times in 741 Posts

    Default Re: JSplitPane divider location always resets to its initial value

    Congrats! There may be a field to be set that would change the divider's default location.

Similar Threads

  1. arraylist keeps reseting initial value?
    By saabro in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 21st, 2013, 01:32 PM
  2. Replies: 4
    Last Post: August 17th, 2012, 11:37 PM
  3. ArrayList initial capacity problem (Index out of bounds Exception)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2011, 12:24 PM
  4. [B]Insert a JFrame and a JTable in a JSplitPane[/B]
    By sincerelibran in forum AWT / Java Swing
    Replies: 1
    Last Post: January 23rd, 2011, 01:59 PM
  5. How to set initial balance of savings account?
    By Punky0214 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 17th, 2010, 10:00 PM