-
Bug
-
Resolution: Fixed
-
P3
-
8u102, 9
-
b34
-
x86_64
-
windows_7
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.
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.
- relates to
-
JDK-8191552 Carefully check each component for its minimum size and preferred size, and have it return a resonable size.
-
- Open
-