Skip to content

Commit 8e6a41d

Browse files
hansonrhansonr
authored andcommitted
swingjs.plaf upgrade - JTable working more smoothly and efficiently
1 parent 458e7bc commit 8e6a41d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1136
-628
lines changed
7.51 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181204022550
1+
20181209152052
7.51 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181204022550
1+
20181209152052
7.51 KB
Binary file not shown.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Oracle or the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
package components;
33+
34+
/*
35+
* SimpleTableDemo.java requires no other files.
36+
*/
37+
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.JScrollPane;
41+
import javax.swing.JTable;
42+
import java.awt.Dimension;
43+
import java.awt.GridLayout;
44+
import java.awt.event.MouseAdapter;
45+
import java.awt.event.MouseEvent;
46+
47+
public class SimpleTableDemo extends JPanel {
48+
private boolean DEBUG = false;
49+
50+
public SimpleTableDemo() {
51+
super(new GridLayout(1,0));
52+
53+
String[] columnNames = {"First Name",
54+
"Last Name",
55+
"Sport",
56+
"# of Years",
57+
"Vegetarian"};
58+
59+
Object[][] data = {
60+
{"Kathy", "Smith",
61+
"Snowboarding", new Integer(5), new Boolean(false)},
62+
{"John", "Doe",
63+
"Rowing", new Integer(3), new Boolean(true)},
64+
{"Sue", "Black",
65+
"Knitting", new Integer(2), new Boolean(false)},
66+
{"Jane", "White",
67+
"Speed reading", new Integer(20), new Boolean(true)},
68+
{"Joe", "Brown",
69+
"Pool", new Integer(10), new Boolean(false)}
70+
};
71+
72+
final JTable table = new JTable(data, columnNames);
73+
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
74+
table.setFillsViewportHeight(true);
75+
76+
if (DEBUG) {
77+
table.addMouseListener(new MouseAdapter() {
78+
public void mouseClicked(MouseEvent e) {
79+
printDebugData(table);
80+
}
81+
});
82+
}
83+
84+
//Create the scroll pane and add the table to it.
85+
JScrollPane scrollPane = new JScrollPane(table);
86+
87+
//Add the scroll pane to this panel.
88+
add(scrollPane);
89+
}
90+
91+
private void printDebugData(JTable table) {
92+
int numRows = table.getRowCount();
93+
int numCols = table.getColumnCount();
94+
javax.swing.table.TableModel model = table.getModel();
95+
96+
System.out.println("Value of data: ");
97+
for (int i=0; i < numRows; i++) {
98+
System.out.print(" row " + i + ":");
99+
for (int j=0; j < numCols; j++) {
100+
System.out.print(" " + model.getValueAt(i, j));
101+
}
102+
System.out.println();
103+
}
104+
System.out.println("--------------------------");
105+
}
106+
107+
/**
108+
* Create the GUI and show it. For thread safety,
109+
* this method should be invoked from the
110+
* event-dispatching thread.
111+
*/
112+
private static void createAndShowGUI() {
113+
//Create and set up the window.
114+
JFrame frame = new JFrame("SimpleTableDemo");
115+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
116+
117+
//Create and set up the content pane.
118+
SimpleTableDemo newContentPane = new SimpleTableDemo();
119+
newContentPane.setOpaque(true); //content panes must be opaque
120+
frame.setContentPane(newContentPane);
121+
122+
//Display the window.
123+
frame.pack();
124+
frame.setVisible(true);
125+
}
126+
127+
public static void main(String[] args) {
128+
//Schedule a job for the event-dispatching thread:
129+
//creating and showing this application's GUI.
130+
javax.swing.SwingUtilities.invokeLater(new Runnable() {
131+
public void run() {
132+
createAndShowGUI();
133+
}
134+
});
135+
}
136+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Oracle or the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
package components;
33+
34+
/*
35+
* TableDemo.java requires no other files.
36+
*/
37+
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.JScrollPane;
41+
import javax.swing.JTable;
42+
import javax.swing.table.AbstractTableModel;
43+
import java.awt.Dimension;
44+
import java.awt.GridLayout;
45+
46+
/**
47+
* TableDemo is just like SimpleTableDemo, except that it uses a custom
48+
* TableModel.
49+
*/
50+
public class TableDemo extends JPanel {
51+
private boolean DEBUG = false;
52+
53+
public TableDemo() {
54+
super(new GridLayout(1, 0));
55+
56+
JTable table = new JTable(new MyTableModel());
57+
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
58+
table.setFillsViewportHeight(true);
59+
60+
// Create the scroll pane and add the table to it.
61+
JScrollPane scrollPane = new JScrollPane(table);
62+
63+
// Add the scroll pane to this panel.
64+
add(scrollPane);
65+
}
66+
67+
class MyTableModel extends AbstractTableModel {
68+
private String[] columnNames = { "Row", "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };
69+
private int i = 0;
70+
private Object[][] data = { { ++i, "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
71+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
72+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
73+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
74+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
75+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
76+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
77+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
78+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
79+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
80+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
81+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
82+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
83+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
84+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
85+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
86+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
87+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
88+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
89+
{ ++i, "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
90+
{ ++i, "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
91+
{ ++i, "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
92+
{ ++i, "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };
93+
94+
public int getColumnCount() {
95+
return columnNames.length;
96+
}
97+
98+
public int getRowCount() {
99+
return data.length;
100+
}
101+
102+
public String getColumnName(int col) {
103+
return columnNames[col];
104+
}
105+
106+
public Object getValueAt(int row, int col) {
107+
return data[row][col];
108+
}
109+
110+
/*
111+
* JTable uses this method to determine the default renderer/ editor for each
112+
* cell. If we didn't implement this method, then the last column would contain
113+
* text ("true"/"false"), rather than a check box.
114+
*/
115+
public Class getColumnClass(int c) {
116+
return getValueAt(0, c).getClass();
117+
}
118+
119+
/*
120+
* Don't need to implement this method unless your table's editable.
121+
*/
122+
public boolean isCellEditable(int row, int col) {
123+
// Note that the data/cell address is constant,
124+
// no matter where the cell appears onscreen.
125+
if (col < 3) {
126+
return false;
127+
} else {
128+
return true;
129+
}
130+
}
131+
132+
/*
133+
* Don't need to implement this method unless your table's data can change.
134+
*/
135+
public void setValueAt(Object value, int row, int col) {
136+
if (DEBUG) {
137+
System.out.println("Setting value at " + row + "," + col + " to " + value + " (an instance of "
138+
+ value.getClass() + ")");
139+
}
140+
141+
data[row][col] = value;
142+
fireTableCellUpdated(row, col);
143+
144+
if (DEBUG) {
145+
System.out.println("New value of data:");
146+
printDebugData();
147+
}
148+
}
149+
150+
private void printDebugData() {
151+
int numRows = getRowCount();
152+
int numCols = getColumnCount();
153+
154+
for (int i = 0; i < numRows; i++) {
155+
System.out.print(" row " + i + ":");
156+
for (int j = 0; j < numCols; j++) {
157+
System.out.print(" " + data[i][j]);
158+
}
159+
System.out.println();
160+
}
161+
System.out.println("--------------------------");
162+
}
163+
}
164+
165+
/**
166+
* Create the GUI and show it. For thread safety, this method should be invoked
167+
* from the event-dispatching thread.
168+
*/
169+
private static void createAndShowGUI() {
170+
// Create and set up the window.
171+
JFrame frame = new JFrame("TableDemo");
172+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
173+
174+
// Create and set up the content pane.
175+
TableDemo newContentPane = new TableDemo();
176+
newContentPane.setOpaque(true); // content panes must be opaque
177+
frame.setContentPane(newContentPane);
178+
179+
// Display the window.
180+
frame.pack();
181+
frame.setVisible(true);
182+
}
183+
184+
public static void main(String[] args) {
185+
// Schedule a job for the event-dispatching thread:
186+
// creating and showing this application's GUI.
187+
javax.swing.SwingUtilities.invokeLater(new Runnable() {
188+
public void run() {
189+
createAndShowGUI();
190+
}
191+
});
192+
}
193+
}

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFGraphics.java

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public Graphics getGraphics() {
165165
// ((ConstrainableGraphics) g).constrain(x, y, width, height);
166166
// } else {
167167
g.translate(x, (isContentPane ? 0 : y));
168-
g.setClip(0, 0, width, height);
168+
g.clipRect(0, 0, width, height); // BH changed 2018.12.05 was setClip
169169
// }
170170
g.setFont(getFont());
171171
return g;
@@ -270,10 +270,10 @@ public void checkBackgroundPainted(JSGraphics2D jsg) {
270270
}
271271
_isBackgroundPainted = jsg.isBackgroundPainted();
272272
if (_isBackgroundPainted) {
273-
((JSComponentUI) ui).setPainted();
273+
((JSComponentUI) ui).setPainted(null);
274274
// It's all one canvas, and it is behind the root pane (bad design?)
275275
// so if it is painted, we should make the root pane transparent
276-
((JSComponentUI) ((JComponent) this).getRootPane().getUI()).setPainted();
276+
((JSComponentUI) ((JComponent) this).getRootPane().getUI()).setPainted(null);
277277
}
278278
}
279279

@@ -327,7 +327,7 @@ public void validateComponent() {
327327
*/
328328
public void paintWithBackgroundCheck(Graphics g) {
329329
checkBackgroundPainted(null);
330-
paint(g);
330+
paint(g);
331331
checkBackgroundPainted(getJSGraphic2D(g));
332332
}
333333

0 commit comments

Comments
 (0)