Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/6937798/bug6937798.java
38854 views
/*1* Copyright (c) 2010, 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 com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;3132import javax.swing.*;33import javax.swing.table.AbstractTableModel;34import javax.swing.table.TableModel;35import java.awt.*;36import java.awt.image.BufferedImage;3738public class bug6937798 {3940public static void main(String... args) throws Exception {41UIManager.setLookAndFeel(new NimbusLookAndFeel());42SwingUtilities.invokeAndWait(new Runnable() {43public void run() {44new bug6937798();45}46});47}4849public bug6937798() {50final JTable table = createCountryTable();51table.setShowGrid(true);52table.setSize(100, 100);5354BufferedImage im = new BufferedImage(table.getWidth(), table.getHeight(), BufferedImage.TYPE_INT_ARGB);55Graphics g = im.getGraphics();56table.print(g);57g.dispose();5859for (int i = 0; i < im.getHeight(); i++) {60for (int j = 0; j < im.getWidth(); j++) {61if (im.getRGB(i, j) == table.getGridColor().getRGB()) {62System.out.println("got it!");63return;64}65}66}67throw new RuntimeException("no table's grid detected....");68}6970protected JTable createCountryTable() {71// Column headers72final String73[] headers = {74"Name", "Capital City", "Language(s)", "Monetary Unit(s)", "EC Member"75};7677// Table data78final Object[][] data = {79{"Albania", "Tirane", "Albanian, Greek", "Lek", new Boolean(false)},80{"Andorra", "Andorra la Vella", "Catalan, French, Spanish", "French Franc, Spanish Peseta", new Boolean(false)},81{"Austria", "Vienna", "German, Slovenian, Croatian", "Schilling", new Boolean(false)},82{"Belarus", "Minsk", "Byelorussian, Russian", "Belarusian Rubel", new Boolean(false)},83{"Belgium", "Brussels", "French, Flemish, German", "Belgian Franc", new Boolean(true)},84{"Bosnia & Herzegovina", "Sarajevo", "Serbo-Croatian", "Dinar", new Boolean(false)},85{"Bulgaria", "Sofia", "Bulgarian, Turkish", "Lev", new Boolean(false)},86{"Croatia", "Zagreb", "Serbo-Croatian", "Croatian Kuna", new Boolean(false)},87{"Czech Republic", "Prague", "Czech, Slovak", "Koruna", new Boolean(false)},88{"Denmark", "Copenhagen", "Danish", "Krone", new Boolean(true)},89{"Estonia", "Tallinn", "Estonian, Latvian, Lithuanian, Russian", "Estonian Kroon", new Boolean(false)},90{"Finland", "Helsinki", "Finnish, Swedish, Lappish", "Markka", new Boolean(false)},91{"France", "Paris", "French", "Franc", new Boolean(true)},92{"Germany", "Berlin", "German", "Deutsche Mark", new Boolean(true)},93{"Greece", "Athens", "Greek, English, French", "Drachma", new Boolean(true)},94{"Hungary", "Budapest", "Hungarian", "Forint", new Boolean(false)},95{"Iceland", "Reykjavik", "Icelandic", "Icelandic Krona", new Boolean(false)},96{"Ireland", "Dublin", "Irish, English", "Pound", new Boolean(true)},97{"Italy", "Rome", "Italian", "Lira", new Boolean(true)},98{"Latvia", "Riga", "Lettish, Lithuanian, Russian", "Lat", new Boolean(false)},99{"Liechtenstein", "Vaduz", "German", "Swiss Franc", new Boolean(false)},100{"Lithuania", "Vilnius", "Lithuanian, Polish, Russian", "Lita", new Boolean(false)},101{"Luxembourg", "Luxembourg", "French, German, Letzeburgesch", "Luxembourg Franc", new Boolean(true)},102{"Macedonia", "Skopje", "Macedonian, Albanian, Turkish, Serbo-Croatian", "Denar", new Boolean(false)},103{"Malta", "Valletta", "Maltese, English", "Maltese Lira", new Boolean(false)},104{"Moldova", "Chisinau", "Moldovan, Russian", "Leu", new Boolean(false)},105{"Monaco", "Monaco", "French, English, Italian", "French Franc", new Boolean(false)},106{"the Netherlands", "Amsterdam", "Dutch", "Guilder", new Boolean(true)},107{"Norway", "Oslo", "Norwegian", "Krone", new Boolean(false)},108{"Poland", "Warsaw", "Polish", "Zloty", new Boolean(false)},109{"Portugal", "Lisbon", "Portuguese", "Escudo", new Boolean(true)},110{"Romania", "Bucharest", "Romanian", "Leu", new Boolean(false)},111{"Russia", "Moscow", "Russian", "Ruble", new Boolean(false)},112{"San Marino", "San Marino", "Italian", "Italian Lira", new Boolean(false)},113{"Slovakia", "Bratislava", "Slovak, Hungarian", "Koruna", new Boolean(false)},114{"Slovenia", "Ljubljana", "Slovenian, Serbo-Croatian", "Tolar", new Boolean(false)},115{"Spain", "Madrid", "Spanish", "Peseta", new Boolean(true)},116{"Sweden", "Stockholm", "Swedish", "Krona", new Boolean(false)},117{"Switzerland", "Bern", "German, French, Italian", "Swiss Franc", new Boolean(false)},118{"Turkey", "Ankara", "Turkish", "Turkish Lira", new Boolean(false)},119{"Ukraine", "Kiev", "Ukranian, Russian, Romanian, Polish, Hungarian", "Hryvnia", new Boolean(false)},120{"United Kingdom", "London", "English, Welsh", "British Pound", new Boolean(true)},121{"Yugoslavia", "Belgrade", "Serbo-Croatian, Slovenian, Macedonian", "Dinar", new Boolean(false)},122};123124// Table model125TableModel dataModel = new AbstractTableModel() {126127public int getColumnCount() {128return headers.length;129}130131public int getRowCount() {132return data.length;133}134135public Object getValueAt(int row, int col) {136return data[row][col];137}138139public String getColumnName(int column) {140return headers[column];141}142143public Class getColumnClass(int col) {144return getValueAt(0, col).getClass();145}146147public void setValueAt(Object aValue, int row, int column) {148data[row][column] = aValue;149}150151public boolean isCellEditable(int row, int col) {152return (col == 4);153}154};155156// Create table with table model157JTable countryTable = new JTable(dataModel);158countryTable.setGridColor(Color.pink);159countryTable.setBackground(Color.white);160countryTable.setForeground(Color.black);161return countryTable;162}163}164165166