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

Label on JButton widget truncated due to layout bug.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: rm29839 Date: 02/19/98


      Run the following application (java B).
      It will create a toolbar with one button in it
      in the "North" region of a border layout panel.
      You'll see that the button has been incorrectly
      resized so that its label text requires
      truncation.
      The label should read "label"; instead it
      reads "la...". This problem seems to be
      related to BorderLayout and the BoxLayout that
      is used by the JToolBar widget.
      -------------------------------------------------
      import java.awt.swing.JButton;
      import java.awt.swing.JToolBar;
      import java.awt.swing.BoxLayout;
      import java.awt.swing.Box;
      import java.awt.swing.JPanel;
      import java.awt.swing.JLabel;
      import java.awt.swing.JFrame;
      import java.awt.Font;
      import java.awt.Container;
      import java.awt.BorderLayout;
      class B {
          public static void main(String args[]){
              JToolBar toolbar = new JToolBar();
              toolbar.add(createButton("Label"));
              JFrame frame = new JFrame();
              Container pane = frame.getContentPane();
              pane.setLayout(new BorderLayout());

              pane.add("North",toolbar);
              pane.add("South",new JLabel("South"));
              pane.add("Center",new JLabel("Center"));
              frame.pack();
              frame.setVisible(true);
              }

          static JButton createButton(String label){
              JButton b = new JButton();
              Font f = b.getFont();
              Font newFont = new Font(f.getName(),f.getStyle(),9);
              b.setFont(newFont);
              b.setText(label);
              return b;
              }

      }
      (Review ID: 25096)
      ======================================================================

            stewilso Steve Wilson (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: