Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4622200

RFE: option for JSplitPane one-touch button to respect min pane size

XMLWordPrintable

      Name: ddT132432 Date: 01/10/2002


      FULL PRODUCT VERSION :
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195] SP2

      ADDITIONAL OPERATING SYSTEMS : none



      A DESCRIPTION OF THE PROBLEM :
      BasicSplitPaneDivider.OneTouchActionHandler hardcodes
      minimum/maximum size based on insets and divider size alone
      rather than using
      getMinimumDividerPosition()/getMaximumDividerPosition(),
      (effectively behaving as if minimum pane size is 0).

      RFE: Extend JSplitPane with the option that makes the
      one-touch zoom buttons respect/obey the pane minimum size.
      E.g.,
            setOneTouchRespectsMinimumPaneSize(true);
          If false, ignores minimum pane size, as now.
          If true, respects minimum pane size.

      Code below illustrates how this is useful for keeping titles
      visible for distinguishing several panes.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run code below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected simple way to make one-touch buttons respect
      minimum pane size.

      Actual: obscure kludge required to make one-touch buttons
      respect minimum pane size, and it is not possible to
      preserve the return-to-previous-center-position behavior,
      since that behavior is hardcoded in action listeners, and
      the action listeners are not easily overridden.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      /** BasicSplitPaneDivider.OneTouchActionHandler hardcodes
          minimum/maximum size based on insets and divider size alone rather
          than using getMinimumDividerPosition()/getMaximumDividerPosition(),
          (effectively behaving as if minimum pane size is 0).

          Example below illustrates usefulness of split panes with titles which
          remain visible while divider is set so most of pane is invisible.
          Apparent approach is to use title size as minimum size, but
          one-touch zoom button does not respect minimum size.
          Partial workaround is to override setDividerLocation to set at min/max
          location if OneTouchActionHandler attempts to set location to edge.
          However, this is not a complete fix, as OneTouchActionHandler
          uses the edge locations to detect when to return to the previous
          center location; because of this, the example below cannot be
          amended to preserve this return-to-previous-center-position behavior.
          
          RFE: Extend JSplitPane with the option that makes the one-touch zoom
          buttons respect/obey the pane minimum size. E.g.,
            setOneTouchRespectsMinimumPaneSize(true);
          If false, ignores minimum pane size, as now.
          If true, respects minimum pane size.
      **/
      public class JSplitPaneRespectingMinPaneSizeTest {
        public static void main(String[] ignore) {
          JFrame frame = new JFrame("JSplitPaneRespectingMinPaneSizeTest");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

          JSplitPane splitPane1 = new SplitPaneRespectingMinPaneSize();
          JSplitPane splitPane2 = new SplitPaneRespectingMinPaneSize();
          JSplitPane splitPane3 = new SplitPaneRespectingMinPaneSize();

          splitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
          splitPane1.setTopComponent(makePane("Input"));
          splitPane1.setBottomComponent(splitPane2);
          
          splitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
          splitPane2.setTopComponent(makePane("Trace Log"));
          splitPane2.setBottomComponent(makePane("Output"));

          frame.getContentPane().add(splitPane1);
          frame.setSize(600,400);
          frame.show();
        }
        public static JPanel makePane(String title) {
          String sampleText =
            "Example of special JSplitPane which attempts to respect\n"+
            "minimum size of pane. (Click the one-touch expand buttons.)\n"+
            "Thus, pane titles stay visible. However, no plaf-general way\n"+
            "to make Divider restore to its previous position with this \n"+
            "approach, so RFE: a JSplitPane option to respect min pane size.\n";
          JPanel panel = new JPanel(new BorderLayout());
          JLabel titleLabel = new JLabel(title);
          panel.add(titleLabel, BorderLayout.NORTH);
          panel.add(new JScrollPane(new JTextArea(sampleText)));
          panel.setMinimumSize(titleLabel.getMinimumSize());
          return panel;
        }

        static class SplitPaneRespectingMinPaneSize extends JSplitPane {
          { setOneTouchExpandable(true); }
          /** Adapts setDividerLocation so one-touch buttons respect min pane sizes**/
          public void setDividerLocation(int loc) {
            Dimension size = getSize();
            Insets insets = getInsets();
            int dividerThickness = getDividerSize();
            if (getOrientation() == JSplitPane.VERTICAL_SPLIT) {
      if (loc == insets.top)
      loc = getMinimumDividerLocation(); // zoom button made too low, fix
      else if (loc == size.height - dividerThickness - insets.bottom)
      loc = getMaximumDividerLocation(); // zoom button made too high, fix
      // else leave loc as is.
            } else { /** JSplitPane.HORIZONTAL_SPLIT **/
      if (loc == insets.left)
                loc = getMinimumDividerLocation(); // zoom button made too low, fix
      else if (loc == size.width - dividerThickness - insets.right)
      loc = getMaximumDividerLocation(); // zoom button made too high, fix
      // else leave loc as is.
            }
            super.setDividerLocation(loc);
          }
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Code provides only partial workaround by overriding
      setDividerLocation.
      (Review ID: 137906)
      ======================================================================

            Unassigned Unassigned
            ddressersunw Daniel Dresser (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: