--- /dev/null 2017-10-31 17:18:56.000000000 +0530 +++ new/test/jdk/javax/swing/JMenu/8178430/LabelDotTest.java 2017-10-31 17:18:54.389224800 +0530 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8178430 + * @summary JMenu in GridBagLayout flickers when label text shows "..." and + * is updated + * @run main LabelDotTest + */ +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.stream.IntStream; + +import javax.swing.SwingUtilities; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JFrame; +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); + + new Thread(() -> IntStream.range(0, 10).forEach((i) -> { + if ( label.getText().equals(shortText) ) { + label.setText(longText); + } else { + label.setText(shortText); + } + + /* + For a top level menu item, minimum size and the preferred + size should be the same, and should not be equal to 1 + */ + if (menu.getMinimumSize().height == 1 && + !menu.getMinimumSize().equals(menu.getPreferredSize())) + throw new RuntimeException("Size of Menu bar is not correct."); + + try { + Thread.sleep(1000); + } + catch( InterruptedException e ) { } + + if (i >= 9) + frame.dispose(); + }) + ).start(); + } + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(() -> new LabelDotTest()); + } +}