# HG changeset patch # User azvegint # Date 1441783919 -10800 # Node ID 97d6f025486075536e89aa7ad7eed886cc2d6147 # Parent 413efa102b75a06642a530ce6ce067468f10dbac 8005914: [TEST_BUG] The last column header does not contain "..." Reviewed-by: alexsch, serb Contributed-by: shilpi.rastogi@oracle.com diff -r 413efa102b75 -r 97d6f0254860 jdk/test/javax/swing/JTableHeader/6442918/bug6442918a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JTableHeader/6442918/bug6442918a.java Wed Sep 09 10:31:59 2015 +0300 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015, 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 6442918 8005914 + @summary Ensures that empty table headers do not show "..." + @author Shannon Hickey + @library ../../regtesthelpers + @build Util + @run main/manual bug6442918a + @requires os.family == "windows" +*/ + +import java.awt.BorderLayout; +import java.awt.Dimension; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.table.DefaultTableCellRenderer; + + +public class bug6442918a { + + public static void main(String[] args) throws Throwable, Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf" + + ".windows.WindowsLookAndFeel"); + } catch (Exception e) { + // test is for Windows look and feel + throw new RuntimeException("Test is only for WLaF." + + e.getMessage()); + } + runTest(); + } + }); + } + + private static void runTest() { + JDialog dialog = Util + .createModalDialogWithPassFailButtons("Empty header showing \"...\""); + String[] columnNames = {"", "", "", "", "Testing"}; + String[][] data = {{"1", "2", "3", "4", "5"}}; + JTable table = new JTable(data, columnNames); + DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); + int tableCellWidth = renderer.getFontMetrics(renderer.getFont()) + .stringWidth("test"); + table.setPreferredScrollableViewportSize(new Dimension( + 5 * tableCellWidth, 50)); + JPanel p = new JPanel(); + p.add(new JScrollPane(table)); + dialog.add(p, BorderLayout.NORTH); + JTextArea area = new JTextArea(); + String txt = "\nInstructions:\n\n"; + txt += "Only the last column header should show \"...\"."; + area.setText(txt); + dialog.add(new JScrollPane(area), BorderLayout.CENTER); + dialog.pack(); + dialog.setVisible(true); + } +} diff -r 413efa102b75 -r 97d6f0254860 jdk/test/javax/swing/regtesthelpers/Util.java --- a/jdk/test/javax/swing/regtesthelpers/Util.java Tue Sep 08 15:19:19 2015 -0700 +++ b/jdk/test/javax/swing/regtesthelpers/Util.java Wed Sep 09 10:31:59 2015 +0300 @@ -41,6 +41,7 @@ */ public class Util { + /** * Convert a rectangle from coordinate system of Component c to * screen coordinate system. @@ -266,4 +267,42 @@ result.add(KeyEvent.VK_ALT); return result; } + + /** + * Creates and returns a JDialog with two button, one that says pass, + * another that says fail. The fail button is wired to call + * uiTestFailed with failString and the pass + * button is wired to invoked uiTestPassed. + *

The content pane of the JDialog uses a BorderLayout with the + * buttons inside a horizontal box with filler between them and the + * pass button on the left. + *

The returned Dialog has not been packed, or made visible, it is + * up to the caller to do that (after putting in some useful components). + */ + public static JDialog createModalDialogWithPassFailButtons(final String failString) { + JDialog retDialog = new JDialog(); + Box buttonBox = Box.createHorizontalBox(); + JButton passButton = new JButton("Pass"); + JButton failButton = new JButton("Fail"); + + passButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + retDialog.dispose(); + } + }); + failButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + retDialog.dispose(); + throw new RuntimeException("Test failed. " + failString); + } + }); + retDialog.setTitle("Test"); + retDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); + buttonBox.add(passButton); + buttonBox.add(Box.createGlue()); + buttonBox.add(failButton); + retDialog.getContentPane().add(buttonBox, BorderLayout.SOUTH); + retDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + return retDialog; + } }