Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 805
  • Last Modified:

JScrollPane & JFrame resize problem

Is there a possibility to know the difference between a user changing the divider location of a splitpane and the user
changing the framesize so that the divider location changes accordingly?

The problem is as follows:

I have added several nested vertically split JSplitPanes to a frame. The user must be able to change the divider location.
But when I resize the frame, the dividerlocation must stay the same. To accomplish this, I have added the JSplitPane
containing all the other SplitPanes to a JScrollPane. This ScrollPane works, but only after the minimum height of each
JSplitPane has been reached (ic. the height of a JLabel on it). What I want to achieve is that the user can change the
dividerlocations when he wants to, but that they stay the same when he resizes the frame.
I thought of saving the divider location when the user changed the location and then resetting it in the repaint() method.
When the user resizes the frame it should only get the previous divider locations and reset them.

I have started to override the repaint() but I need to know the difference between the frame resizing and the user dragging the divider location.

public void repaint () {
     try {
          if (jsp != null) { // jsp is the JScrollPane
               JSplitPane split = null, parentSplit;
               // go to the inner nested JSplitPane
               split = (JSplitPane) first.getBottomComponent();
               do {
                    split = (JSplitPane) split.getBottomComponent();
               } while ( split.getBottomComponent() instanceof JSplitPane);

               // get the parent and set the divider location
               parentSplit = (JSplitPane) split.getParent();
               do {
                    split.setDividerLocation ( /*preferredLocation */);
                    try {
                         parentSplit = (JSplitPane) parentSplit.getParent ();
//                         Print.pln("dividerlocation "+parentSplit.getDividerLocation ());
                    } catch (ClassCastException cce) { break; }
               } while ( parentSplit instanceof JSplitPane);
     } catch (Exception e) { Print.pln ("SplitPaneDesign exception :"+e); }

Is this possible?

Thanks for any help!

1 Solution

can't you just set the resizeWeight on all your splitpanes to 0.0d?

That way, the left/top component will not resize when the window does...

Maybe I've got the wrong end of the stick though...

JSplitPane.setResizeWeight( double weight ) ;
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now