Path: blob/master/test/jdk/javax/swing/JTable/6937798/bug6937798.java
41153 views
/*1* Copyright (c) 2010, 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 693779825@summary Nimbus: Issues with JTable grid26@author Alexander Potochkin27@run main bug693779828*/2930import javax.swing.*;31import javax.swing.plaf.nimbus.NimbusLookAndFeel;32import javax.swing.table.AbstractTableModel;33import javax.swing.table.TableModel;34import java.awt.*;35import java.awt.image.BufferedImage;3637public class bug6937798 {3839public static void main(String... args) throws Exception {40UIManager.setLookAndFeel(new NimbusLookAndFeel());41SwingUtilities.invokeAndWait(new Runnable() {42public void run() {43new bug6937798();44}45});46}4748public bug6937798() {49final JTable table = createCountryTable();50table.setShowGrid(true);51table.setSize(100, 100);5253BufferedImage im = new BufferedImage(table.getWidth(), table.getHeight(), BufferedImage.TYPE_INT_ARGB);54Graphics g = im.getGraphics();55table.print(g);56g.dispose();5758for (int i = 0; i < im.getHeight(); i++) {59for (int j = 0; j < im.getWidth(); j++) {60if (im.getRGB(i, j) == table.getGridColor().getRGB()) {61System.out.println("got it!");62return;63}64}65}66throw new RuntimeException("no table's grid detected....");67}6869protected JTable createCountryTable() {70// Column headers71final String72[] headers = {73"Name", "Capital City", "Language(s)", "Monetary Unit(s)", "EC Member"74};7576// Table data77final Object[][] data = {78{"Albania", "Tirane", "Albanian, Greek", "Lek", new Boolean(false)},79{"Andorra", "Andorra la Vella", "Catalan, French, Spanish", "French Franc, Spanish Peseta", new Boolean(false)},80{"Austria", "Vienna", "German, Slovenian, Croatian", "Schilling", new Boolean(false)},81{"Belarus", "Minsk", "Byelorussian, Russian", "Belarusian Rubel", new Boolean(false)},82{"Belgium", "Brussels", "French, Flemish, German", "Belgian Franc", new Boolean(true)},83{"Bosnia & Herzegovina", "Sarajevo", "Serbo-Croatian", "Dinar", new Boolean(false)},84{"Bulgaria", "Sofia", "Bulgarian, Turkish", "Lev", new Boolean(false)},85{"Croatia", "Zagreb", "Serbo-Croatian", "Croatian Kuna", new Boolean(false)},86{"Czech Republic", "Prague", "Czech, Slovak", "Koruna", new Boolean(false)},87{"Denmark", "Copenhagen", "Danish", "Krone", new Boolean(true)},88{"Estonia", "Tallinn", "Estonian, Latvian, Lithuanian, Russian", "Estonian Kroon", new Boolean(false)},89{"Finland", "Helsinki", "Finnish, Swedish, Lappish", "Markka", new Boolean(false)},90{"France", "Paris", "French", "Franc", new Boolean(true)},91{"Germany", "Berlin", "German", "Deutsche Mark", new Boolean(true)},92{"Greece", "Athens", "Greek, English, French", "Drachma", new Boolean(true)},93{"Hungary", "Budapest", "Hungarian", "Forint", new Boolean(false)},94{"Iceland", "Reykjavik", "Icelandic", "Icelandic Krona", new Boolean(false)},95{"Ireland", "Dublin", "Irish, English", "Pound", new Boolean(true)},96{"Italy", "Rome", "Italian", "Lira", new Boolean(true)},97{"Latvia", "Riga", "Lettish, Lithuanian, Russian", "Lat", new Boolean(false)},98{"Liechtenstein", "Vaduz", "German", "Swiss Franc", new Boolean(false)},99{"Lithuania", "Vilnius", "Lithuanian, Polish, Russian", "Lita", new Boolean(false)},100{"Luxembourg", "Luxembourg", "French, German, Letzeburgesch", "Luxembourg Franc", new Boolean(true)},101{"Macedonia", "Skopje", "Macedonian, Albanian, Turkish, Serbo-Croatian", "Denar", new Boolean(false)},102{"Malta", "Valletta", "Maltese, English", "Maltese Lira", new Boolean(false)},103{"Moldova", "Chisinau", "Moldovan, Russian", "Leu", new Boolean(false)},104{"Monaco", "Monaco", "French, English, Italian", "French Franc", new Boolean(false)},105{"the Netherlands", "Amsterdam", "Dutch", "Guilder", new Boolean(true)},106{"Norway", "Oslo", "Norwegian", "Krone", new Boolean(false)},107{"Poland", "Warsaw", "Polish", "Zloty", new Boolean(false)},108{"Portugal", "Lisbon", "Portuguese", "Escudo", new Boolean(true)},109{"Romania", "Bucharest", "Romanian", "Leu", new Boolean(false)},110{"Russia", "Moscow", "Russian", "Ruble", new Boolean(false)},111{"San Marino", "San Marino", "Italian", "Italian Lira", new Boolean(false)},112{"Slovakia", "Bratislava", "Slovak, Hungarian", "Koruna", new Boolean(false)},113{"Slovenia", "Ljubljana", "Slovenian, Serbo-Croatian", "Tolar", new Boolean(false)},114{"Spain", "Madrid", "Spanish", "Peseta", new Boolean(true)},115{"Sweden", "Stockholm", "Swedish", "Krona", new Boolean(false)},116{"Switzerland", "Bern", "German, French, Italian", "Swiss Franc", new Boolean(false)},117{"Turkey", "Ankara", "Turkish", "Turkish Lira", new Boolean(false)},118{"Ukraine", "Kiev", "Ukranian, Russian, Romanian, Polish, Hungarian", "Hryvnia", new Boolean(false)},119{"United Kingdom", "London", "English, Welsh", "British Pound", new Boolean(true)},120{"Yugoslavia", "Belgrade", "Serbo-Croatian, Slovenian, Macedonian", "Dinar", new Boolean(false)},121};122123// Table model124TableModel dataModel = new AbstractTableModel() {125126public int getColumnCount() {127return headers.length;128}129130public int getRowCount() {131return data.length;132}133134public Object getValueAt(int row, int col) {135return data[row][col];136}137138public String getColumnName(int column) {139return headers[column];140}141142public Class getColumnClass(int col) {143return getValueAt(0, col).getClass();144}145146public void setValueAt(Object aValue, int row, int column) {147data[row][column] = aValue;148}149150public boolean isCellEditable(int row, int col) {151return (col == 4);152}153};154155// Create table with table model156JTable countryTable = new JTable(dataModel);157countryTable.setGridColor(Color.pink);158countryTable.setBackground(Color.white);159countryTable.setForeground(Color.black);160return countryTable;161}162}163164165