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

TitledBorder spacing gaps should be adjustable (Bug and RFE)

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: ssT124754 Date: 02/01/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      BUG:
      Trying to use a 'javax.swing.border.TitledBorder' to outline my JComponents, I
      noticed a significant vertical gap always appearing below the text of the title
      of the TitledBorder and above the object it outlined. This eats into the
      vertical real estate I have available for my apps. For example, in the code
      fragment (to be put in some applet's init() method)

        JTextPane textPane = new JTextPane();
        JScrollPane scrollPane = new JScrollPane(textPane);
        scrollPane.setVerticalScrollBarPolicy
      (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setPreferredSize(new Dimension(((Applet) this).getSize().width -
      18, 75));
        JPanel somePane = new JPanel(false);
        somePane.add(scrollPane);
        somePane.setBorder(new TitledBorder(LineBorder.createGrayLineBorder
      (), "Instructions"));
        this.add(somePane);

      you'll see that the title "Instructions" has a substantial gap below it but
      before the JScrollPane. I looked through the source of TitledBorder and found
      the problem in the 'getBorderInsets(Component, Insets)' method.
      There is a switch statement 'switch(getTitlePosition())' that has
      a case statement matching 'TOP' that has the following body:

           case TOP:
           case DEFAULT_POSITION:
               insets.top += ascent + descent;
               break;

      and I believe it should read...

           case TOP:
           case DEFAULT_POSITION:
               insets.top += (ascent / 2) + descent;
               break;

      since the title is vertically centered in the border. The same holds for the
      'BOTTOM' case statement of that switch.

      RFE:
        After developing my workaround, I wondered if it would simply be possible to
      create some accessor methods so that the user could pad the space with pixels
      to increase or decrease this buffer zone (and other buffers used throughout the
      class) on an individual basis. Something like

           case TOP:
           case DEFAULT_POSITION:
               insets.top += (ascent / 2) + descent + this.getInternalTopPadding();
               break;
      (Review ID: 115872)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ssultanasunw Shaheen Sultana (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: