Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/6937798/bug6937798.java
38854 views
1
/*
2
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
@bug 6937798
26
@summary Nimbus: Issues with JTable grid
27
@author Alexander Potochkin
28
@run main bug6937798
29
*/
30
31
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
32
33
import javax.swing.*;
34
import javax.swing.table.AbstractTableModel;
35
import javax.swing.table.TableModel;
36
import java.awt.*;
37
import java.awt.image.BufferedImage;
38
39
public class bug6937798 {
40
41
public static void main(String... args) throws Exception {
42
UIManager.setLookAndFeel(new NimbusLookAndFeel());
43
SwingUtilities.invokeAndWait(new Runnable() {
44
public void run() {
45
new bug6937798();
46
}
47
});
48
}
49
50
public bug6937798() {
51
final JTable table = createCountryTable();
52
table.setShowGrid(true);
53
table.setSize(100, 100);
54
55
BufferedImage im = new BufferedImage(table.getWidth(), table.getHeight(), BufferedImage.TYPE_INT_ARGB);
56
Graphics g = im.getGraphics();
57
table.print(g);
58
g.dispose();
59
60
for (int i = 0; i < im.getHeight(); i++) {
61
for (int j = 0; j < im.getWidth(); j++) {
62
if (im.getRGB(i, j) == table.getGridColor().getRGB()) {
63
System.out.println("got it!");
64
return;
65
}
66
}
67
}
68
throw new RuntimeException("no table's grid detected....");
69
}
70
71
protected JTable createCountryTable() {
72
// Column headers
73
final String
74
[] headers = {
75
"Name", "Capital City", "Language(s)", "Monetary Unit(s)", "EC Member"
76
};
77
78
// Table data
79
final Object[][] data = {
80
{"Albania", "Tirane", "Albanian, Greek", "Lek", new Boolean(false)},
81
{"Andorra", "Andorra la Vella", "Catalan, French, Spanish", "French Franc, Spanish Peseta", new Boolean(false)},
82
{"Austria", "Vienna", "German, Slovenian, Croatian", "Schilling", new Boolean(false)},
83
{"Belarus", "Minsk", "Byelorussian, Russian", "Belarusian Rubel", new Boolean(false)},
84
{"Belgium", "Brussels", "French, Flemish, German", "Belgian Franc", new Boolean(true)},
85
{"Bosnia & Herzegovina", "Sarajevo", "Serbo-Croatian", "Dinar", new Boolean(false)},
86
{"Bulgaria", "Sofia", "Bulgarian, Turkish", "Lev", new Boolean(false)},
87
{"Croatia", "Zagreb", "Serbo-Croatian", "Croatian Kuna", new Boolean(false)},
88
{"Czech Republic", "Prague", "Czech, Slovak", "Koruna", new Boolean(false)},
89
{"Denmark", "Copenhagen", "Danish", "Krone", new Boolean(true)},
90
{"Estonia", "Tallinn", "Estonian, Latvian, Lithuanian, Russian", "Estonian Kroon", new Boolean(false)},
91
{"Finland", "Helsinki", "Finnish, Swedish, Lappish", "Markka", new Boolean(false)},
92
{"France", "Paris", "French", "Franc", new Boolean(true)},
93
{"Germany", "Berlin", "German", "Deutsche Mark", new Boolean(true)},
94
{"Greece", "Athens", "Greek, English, French", "Drachma", new Boolean(true)},
95
{"Hungary", "Budapest", "Hungarian", "Forint", new Boolean(false)},
96
{"Iceland", "Reykjavik", "Icelandic", "Icelandic Krona", new Boolean(false)},
97
{"Ireland", "Dublin", "Irish, English", "Pound", new Boolean(true)},
98
{"Italy", "Rome", "Italian", "Lira", new Boolean(true)},
99
{"Latvia", "Riga", "Lettish, Lithuanian, Russian", "Lat", new Boolean(false)},
100
{"Liechtenstein", "Vaduz", "German", "Swiss Franc", new Boolean(false)},
101
{"Lithuania", "Vilnius", "Lithuanian, Polish, Russian", "Lita", new Boolean(false)},
102
{"Luxembourg", "Luxembourg", "French, German, Letzeburgesch", "Luxembourg Franc", new Boolean(true)},
103
{"Macedonia", "Skopje", "Macedonian, Albanian, Turkish, Serbo-Croatian", "Denar", new Boolean(false)},
104
{"Malta", "Valletta", "Maltese, English", "Maltese Lira", new Boolean(false)},
105
{"Moldova", "Chisinau", "Moldovan, Russian", "Leu", new Boolean(false)},
106
{"Monaco", "Monaco", "French, English, Italian", "French Franc", new Boolean(false)},
107
{"the Netherlands", "Amsterdam", "Dutch", "Guilder", new Boolean(true)},
108
{"Norway", "Oslo", "Norwegian", "Krone", new Boolean(false)},
109
{"Poland", "Warsaw", "Polish", "Zloty", new Boolean(false)},
110
{"Portugal", "Lisbon", "Portuguese", "Escudo", new Boolean(true)},
111
{"Romania", "Bucharest", "Romanian", "Leu", new Boolean(false)},
112
{"Russia", "Moscow", "Russian", "Ruble", new Boolean(false)},
113
{"San Marino", "San Marino", "Italian", "Italian Lira", new Boolean(false)},
114
{"Slovakia", "Bratislava", "Slovak, Hungarian", "Koruna", new Boolean(false)},
115
{"Slovenia", "Ljubljana", "Slovenian, Serbo-Croatian", "Tolar", new Boolean(false)},
116
{"Spain", "Madrid", "Spanish", "Peseta", new Boolean(true)},
117
{"Sweden", "Stockholm", "Swedish", "Krona", new Boolean(false)},
118
{"Switzerland", "Bern", "German, French, Italian", "Swiss Franc", new Boolean(false)},
119
{"Turkey", "Ankara", "Turkish", "Turkish Lira", new Boolean(false)},
120
{"Ukraine", "Kiev", "Ukranian, Russian, Romanian, Polish, Hungarian", "Hryvnia", new Boolean(false)},
121
{"United Kingdom", "London", "English, Welsh", "British Pound", new Boolean(true)},
122
{"Yugoslavia", "Belgrade", "Serbo-Croatian, Slovenian, Macedonian", "Dinar", new Boolean(false)},
123
};
124
125
// Table model
126
TableModel dataModel = new AbstractTableModel() {
127
128
public int getColumnCount() {
129
return headers.length;
130
}
131
132
public int getRowCount() {
133
return data.length;
134
}
135
136
public Object getValueAt(int row, int col) {
137
return data[row][col];
138
}
139
140
public String getColumnName(int column) {
141
return headers[column];
142
}
143
144
public Class getColumnClass(int col) {
145
return getValueAt(0, col).getClass();
146
}
147
148
public void setValueAt(Object aValue, int row, int column) {
149
data[row][column] = aValue;
150
}
151
152
public boolean isCellEditable(int row, int col) {
153
return (col == 4);
154
}
155
};
156
157
// Create table with table model
158
JTable countryTable = new JTable(dataModel);
159
countryTable.setGridColor(Color.pink);
160
countryTable.setBackground(Color.white);
161
countryTable.setForeground(Color.black);
162
return countryTable;
163
}
164
}
165
166