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

JLabel with <html> always line wraps at emojis with Windows zoom

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      openjdk version "11.0.11" 2021-04-20 LTS
      OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
      OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Labels that use HTML are wrapping before emoticons, while non-HTML label don't. Like the title mentions, this only happens if zoom is enabled in Windows. It doesn't seem to matter what zoom level is used. In our case we used 125% though.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      0. Set Windows system zoom to 125%
      1. Create a JLabel
      2. Set the following text "<html>TEXT 🦁</html>"
      3. Put the JLabel into a JFrame
      4. Show the frame

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      None of the labels should line wrap, since there's enough horizontal space availale.
      ACTUAL -
      The labels that wrap their content in <html></html> wrap without the need to do so.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.GridLayout;

      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.WindowConstants;

      public class Buggy
      {
        public static void main( final String[] args )
        {
          final JFrame frame = new JFrame();
          final JLabel labelA = new JLabel( "<html>HTML Emoji character 🦁</html>" );
          final JLabel labelB = new JLabel( "<html>HTML Emoji escape sequence &#129409;</html>" );
          final JLabel labelC = new JLabel( "Emoji character 🦁" );
          //To show there's enough space inside the label and show where each label starts and ends.
          labelA.setOpaque( true );
          labelA.setBackground( Color.YELLOW );
          labelB.setOpaque( true );
          labelB.setBackground( Color.GREEN );
          labelC.setOpaque( true );
          labelC.setBackground( Color.RED );
          frame.setLayout( new GridLayout( 3, 1 ) );
          frame.add( labelA );
          frame.add( labelB );
          frame.add( labelC );
          frame.setSize( 400, 300 );
          frame.setLocationRelativeTo( null );
          frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
          frame.setVisible( true );
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            rmahajan Rajat Mahajan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: