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

TitledBorder's minimum size is not big enough for its title

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6u14
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      java version "1.6.0_14"
      Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
      Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

      Does this problem occur on J2SE 5.0.x or 6.0? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Client: Microsoft Windows XP [Version 5.1.2600]

      Bug Description:
      TitledBorder's minimum size is not big enough for its title

      The TitledBorder JavaDoc for getMinimumSize says:
          /**
           * Returns the minimum dimensions this border requires
           * in order to fully display the border and title.
           * @param c the component where this border will be drawn
           */
      however this size is always one or 2 characters smaller than it needs to be so the remaining characters are getting cut off.

      Expected: the border to show 'Test'
      Actual: the border shows 'Tes'

      import static java.lang.System.*;
      import static java.lang.Math.*;
      import static javax.swing.BorderFactory.*;
      import static javax.swing.JFrame.*;
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.border.*;

      public class Test {
        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            JFrame frame = new JFrame();
            frame.setLayout(new FlowLayout());
            JPanel panel = new JPanel() {
              @Override
              public Dimension getPreferredSize() {
                /** todo remove this method once sun bug 4994231 is fixed */
                Border border = getBorder();
                if (border instanceof TitledBorder) {
                  Dimension size = super.getPreferredSize();
                  Dimension borderSize = ((TitledBorder)border).getMinimumSize(this);
                  return new Dimension(max(size.width, borderSize.width), max(size.height,
                      borderSize.height));
                }
                return super.getPreferredSize();
              }

              @Override
              public Dimension getMinimumSize() {
                /** todo remove this method once sun bug 4994231 is fixed */
                Border border = getBorder();
                if (border instanceof TitledBorder) {
                  Dimension size = super.getMinimumSize();
                  Dimension borderSize = ((TitledBorder)border).getMinimumSize(this);
                  return new Dimension(max(size.width, borderSize.width), max(size.height,
                      borderSize.height));
                }
                return super.getMinimumSize();
              }
            };
            panel.setBorder(createTitledBorder("Test"));
            frame.add(panel);
            frame.setSize(500, 500);
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.setVisible(true);
          }
          catch (Exception ex) {
            out.println(ex);
          }
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                tyao Ting-Yun Ingrid Yao (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: