Path: blob/master/test/jdk/javax/swing/JTableHeader/6442918/bug6442918a.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 6442918 800591425@summary Ensures that empty table headers do not show "..."26@author Shannon Hickey27@library ../../regtesthelpers28@build Util29@run main/manual bug6442918a30@requires os.family == "windows"31*/3233import java.awt.BorderLayout;34import java.awt.Dimension;35import javax.swing.JDialog;36import javax.swing.JFrame;37import javax.swing.JPanel;38import javax.swing.JScrollPane;39import javax.swing.JTable;40import javax.swing.JTextArea;41import javax.swing.SwingUtilities;42import javax.swing.UIManager;43import javax.swing.table.DefaultTableCellRenderer;444546public class bug6442918a {4748public static void main(String[] args) throws Throwable, Exception {49SwingUtilities.invokeAndWait(new Runnable() {50public void run() {51try {52UIManager.setLookAndFeel("com.sun.java.swing.plaf"53+ ".windows.WindowsLookAndFeel");54} catch (Exception e) {55// test is for Windows look and feel56throw new RuntimeException("Test is only for WLaF."57+ e.getMessage());58}59runTest();60}61});62}6364private static void runTest() {65JDialog dialog = Util66.createModalDialogWithPassFailButtons("Empty header showing \"...\"");67String[] columnNames = {"", "", "", "", "Testing"};68String[][] data = {{"1", "2", "3", "4", "5"}};69JTable table = new JTable(data, columnNames);70DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();71int tableCellWidth = renderer.getFontMetrics(renderer.getFont())72.stringWidth("test");73table.setPreferredScrollableViewportSize(new Dimension(745 * tableCellWidth, 50));75JPanel p = new JPanel();76p.add(new JScrollPane(table));77dialog.add(p, BorderLayout.NORTH);78JTextArea area = new JTextArea();79String txt = "\nInstructions:\n\n";80txt += "Only the last column header should show \"...\".";81area.setText(txt);82dialog.add(new JScrollPane(area), BorderLayout.CENTER);83dialog.pack();84dialog.setVisible(true);85}86}878889