Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/6937798/bug6937798.java
41153 views
1
/*
2
* Copyright (c) 2010, 2015, 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 javax.swing.*;
32
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
33
import javax.swing.table.AbstractTableModel;
34
import javax.swing.table.TableModel;
35
import java.awt.*;
36
import java.awt.image.BufferedImage;
37
38
public class bug6937798 {
39
40
public static void main(String... args) throws Exception {
41
UIManager.setLookAndFeel(new NimbusLookAndFeel());
42
SwingUtilities.invokeAndWait(new Runnable() {
43
public void run() {
44
new bug6937798();
45
}
46
});
47
}
48
49
public bug6937798() {
50
final JTable table = createCountryTable();
51
table.setShowGrid(true);
52
table.setSize(100, 100);
53
54
BufferedImage im = new BufferedImage(table.getWidth(), table.getHeight(), BufferedImage.TYPE_INT_ARGB);
55
Graphics g = im.getGraphics();
56
table.print(g);
57
g.dispose();
58
59
for (int i = 0; i < im.getHeight(); i++) {
60
for (int j = 0; j < im.getWidth(); j++) {
61
if (im.getRGB(i, j) == table.getGridColor().getRGB()) {
62
System.out.println("got it!");
63
return;
64
}
65
}
66
}
67
throw new RuntimeException("no table's grid detected....");
68
}
69
70
protected JTable createCountryTable() {
71
// Column headers
72
final String
73
[] headers = {
74
"Name", "Capital City", "Language(s)", "Monetary Unit(s)", "EC Member"
75
};
76
77
// Table data
78
final 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
};
123
124
// Table model
125
TableModel dataModel = new AbstractTableModel() {
126
127
public int getColumnCount() {
128
return headers.length;
129
}
130
131
public int getRowCount() {
132
return data.length;
133
}
134
135
public Object getValueAt(int row, int col) {
136
return data[row][col];
137
}
138
139
public String getColumnName(int column) {
140
return headers[column];
141
}
142
143
public Class getColumnClass(int col) {
144
return getValueAt(0, col).getClass();
145
}
146
147
public void setValueAt(Object aValue, int row, int column) {
148
data[row][column] = aValue;
149
}
150
151
public boolean isCellEditable(int row, int col) {
152
return (col == 4);
153
}
154
};
155
156
// Create table with table model
157
JTable countryTable = new JTable(dataModel);
158
countryTable.setGridColor(Color.pink);
159
countryTable.setBackground(Color.white);
160
countryTable.setForeground(Color.black);
161
return countryTable;
162
}
163
}
164
165