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

JMenu in GridBagLayout flickers when label text shows "..." and is updated

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b34
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_91"
      Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      A JMenu inside a frame with GridBagLayout partly vanishes and reappears when the frame also contains a label which text is updated frequently and the text is sometimes shortened with "..." and sometimes not.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute test program.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The menu remains stable.
      ACTUAL -
      The menu partly vanishes when the long shortened text is shown in the label at the bottom. It reappears when the short text is shown in the label.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;

      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JPanel;
      import javax.swing.SwingConstants;


      public class LabelDotTest
      {
      // private final static String longText = "nur anders";
          private final static String longText = "show a very long text to have it automatically shortened";
          private final static String shortText = "show short text";

          private JLabel label = null;
          private JMenu menu = null;
          
          public LabelDotTest()
          {
              System.out.println("BEFORE CREATION");
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(new Dimension(50, 150));
              frame.setLocationRelativeTo(null);

              frame.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
              c.weightx = 1.0;
              c.weighty = 0.0;
              c.gridwidth = GridBagConstraints.REMAINDER;

              JMenuBar menuBar = new JMenuBar();
              menu = new JMenu("Menu");
              menuBar.add(menu);
              frame.add(menuBar, c);
              
              frame.add(new JLabel("Title", SwingConstants.CENTER), c);

              c.weighty = 1.0;
              frame.add(new JPanel(new GridBagLayout()), c);
              c.weighty = 0.0;

              label = new JLabel(shortText);
              frame.add(label, c);

              frame.setVisible(true);

              // Thread starten, der ständig den Text im Label größer und kleiner macht
              new Thread(new Runnable()
              {
                  public void run()
                  {
                      int i = 0;
                      while ( i < 50 )
                      {
                          i++;

                          if ( label.getText().equals(shortText) )
                          {
                              label.setText(longText);
                          }
                          else
                          {
                              label.setText(shortText);
                          }

                          try
                          {
                              Thread.sleep(1000);
                          }
                          catch( InterruptedException e ) { }
                      }
                  }
              } ).start();
          }

          public static void main(String[] args)
          {
              new LabelDotTest();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Add the menu via frame.setJMenu(menubar) to the frame.
      That requires an additional line and space is rare in my use case.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kaddepalli Krishna Addepalli
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: