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

GUI can lose space between word with Metal look and feel

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux_redhat_7.3

      Description

      ADDITIONAL SYSTEM INFORMATION :
      I see this problem on RHEL 7.7

      java -version
      openjdk version "11.0.5" 2019-10-15 LTS
      OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS)
      OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      When a metal look and feel theme overrides getControlTextFont():
        public FontUIResource getControlTextFont() {
              FontUIResource r = new FontUIResource(new Font("Dialog", 0, 12));
              return r;
          }
      And this theme is applied, when the first label drawn starts with a space, then all spaces seem to be lost
      between words on all the labels of the application.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the supplied source code, the GUI will not have spaces between words. Remove the first space from
      the jLabel1's label, recompile and run, the GUI will then have spaces between words.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The spaces between words should never go away.
      ACTUAL -
      run the supplied code.

      ---------- BEGIN SOURCE ----------
      file "NewJDialog.java" contents:
      package javaapplication22;

      import static java.util.logging.Level.INFO;
      import java.util.logging.Logger;
      import javax.swing.plaf.metal.DefaultMetalTheme;
      import javax.swing.plaf.metal.MetalLookAndFeel;
      import javax.swing.plaf.metal.MetalTheme;


      public class NewJDialog extends javax.swing.JDialog {

          private static Logger getLogger() {
              return java.util.logging.Logger.getLogger(NewJDialog.class.getName());
          }

          /**
           * Creates new form NewJDialog
           */
          public NewJDialog(java.awt.Frame parent, boolean modal) {
              super(parent, modal);
              initComponents();
          }

          /**
           * This method is called from within the constructor to initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is always
           * regenerated by the Form Editor.
           */
          @SuppressWarnings("unchecked")
          // <editor-fold defaultstate="collapsed" desc="Generated Code">
          private void initComponents() {

              jPanel1 = new javax.swing.JPanel();
              jLabel1 = new javax.swing.JLabel();
              jPanel2 = new javax.swing.JPanel();
              jButton1 = new javax.swing.JButton();
              jPanel3 = new javax.swing.JPanel();
              jLabel2 = new javax.swing.JLabel();

              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

              jLabel1.setText(" jLabel1 1 2 3");
              jPanel1.add(jLabel1);

              getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

              jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

              jButton1.setText("Close");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      jButton1ActionPerformed(evt);
                  }
              });
              jPanel2.add(jButton1);

              getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

              jLabel2.setText(" A lable with spaces");
              jPanel3.add(jLabel2);

              getContentPane().add(jPanel3, java.awt.BorderLayout.PAGE_START);

              pack();
          }// </editor-fold>

          private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
              System.exit(0);
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              /* Set the Nimbus look and feel */
              //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
              /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
               * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
               */
              try {
                  for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                      if ("Metal".equals(info.getName())) {
                          getLogger().log(INFO, "Setting metal look and feel");
                          MetalTheme nmt = new NewMetalTheme();
                          MetalLookAndFeel.setCurrentTheme(nmt);
                          javax.swing.UIManager.setLookAndFeel(info.getClassName());
                          break;
                      }
                  }
              } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
                  java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              }
              //</editor-fold>
              
              //</editor-fold>

              /* Create and display the dialog */
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true);
                      dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                          @Override
                          public void windowClosing(java.awt.event.WindowEvent e) {
                              System.exit(0);
                          }
                      });
                      dialog.setVisible(true);
                  }
              });
          }

          // Variables declaration - do not modify
          private javax.swing.JButton jButton1;
          private javax.swing.JLabel jLabel1;
          private javax.swing.JLabel jLabel2;
          private javax.swing.JPanel jPanel1;
          private javax.swing.JPanel jPanel2;
          private javax.swing.JPanel jPanel3;
          // End of variables declaration
      }

      File NewMetalTheme.java contents:
      package javaapplication22;

      import java.awt.Font;
      import javax.swing.plaf.FontUIResource;
      import javax.swing.plaf.metal.DefaultMetalTheme;


      public class NewMetalTheme extends DefaultMetalTheme {
          @Override
          public FontUIResource getControlTextFont() {
              FontUIResource r = new FontUIResource(new Font("Dialog", 0, 12));
              return r;
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Just not having the first label start with a space is my work around so far.

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              pbansal Pankaj Bansal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: