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

JToggleButton text truncated with Windows L&F

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The text of a JToggleButton using certain characters such as lowercase "x" will be truncated when displayed using the Windows look and feel. This worked in JDK 8, 9, 10.0.1 and stopped working in JDK 10.0.2. It remains broken in JDK 11 and later (including JDK 13 EA).

      REGRESSION : Last worked in version 10.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the provide `WindowsToggleButtonTextTruncation` class.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A toggle button and a regular button both displaying the label "x"
      ACTUAL -
      A toggle button displaying an elipsis ("...") and a regular button displaying "x"

      ---------- BEGIN SOURCE ----------
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javax.swing.BoxLayout;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JToggleButton;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;
      import javax.swing.WindowConstants;

      public class WindowsToggleButtonTextTruncation {
          private static final String LABEL = "x";

          public static void main(String... args) {
              try {
                  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                  Logger.getLogger(WindowsToggleButtonTextTruncation.class.getName()).log(Level.SEVERE, null, ex);
              }

              JFrame frame = new JFrame("Toggle Button Text Truncation");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS));

              frame.add(new JToggleButton(LABEL)); // Toggle button label will be truncated
              frame.add(new JButton(LABEL));

              frame.pack();
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Manually adjust the preferred size

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: