Skip to content

Commit f88c919

Browse files
hansonrhansonr
authored andcommitted
adds more tests to TableDemo
1 parent d36d1a4 commit f88c919

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

sources/net.sf.j2s.java.core/src/test/components/TableDemo.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.awt.Dimension;
3737
import java.awt.Graphics;
3838
import java.awt.GridLayout;
39+
import java.awt.Rectangle;
3940
import java.awt.event.ActionEvent;
4041
import java.awt.event.ActionListener;
4142
import java.awt.event.MouseEvent;
@@ -102,47 +103,55 @@ public void paint(Graphics g) {
102103

103104
public TableDemo() {
104105
table = new JTable();
105-
if (/** @j2sNative false &&*/true)
106-
table.setUI(new BasicTableUI() {
107-
@Override
108-
public void paint(Graphics g, JComponent c) {
106+
if (/** @j2sNative false && */
107+
true)
108+
table.setUI(new BasicTableUI() {
109+
@Override
110+
public void paint(Graphics g, JComponent c) {
109111
// try { throw new NullPointerException();}catch (Exception e) {e.printStackTrace();}
110112
// System.err.println("TableDemoUI g.clip=" + g.getClipBounds());
111-
super.paint(g, c);
112-
113-
}
114-
115-
});
113+
super.paint(g, c);
116114

115+
}
116+
117+
});
117118

118119
table.setRowHeight(40);
119-
//table.setRowHeight(16);
120-
//table.setRowMargin(1);
120+
// table.setRowHeight(16);
121+
// table.setRowMargin(1);
121122
table.setPreferredScrollableViewportSize(new Dimension(500, 300));
122123
table.setFillsViewportHeight(true);
123124

124-
table.setDefaultRenderer(DemoColor.class, new ColorRenderer());
125+
table.setDefaultRenderer(DemoColor.class, new ColorRenderer());
126+
127+
table.setSize(600, 200);
128+
setTableModel(0);
125129

126-
table.setSize(600,200);
127-
setTableModel(0);
128-
129130
// Create the scroll pane and add the table to it.
130131
JScrollPane scrollPane = new JScrollPane(table);
131132

132133
// Add the scroll pane to this panel.
133134
add(scrollPane);
134-
135-
JButton btn = new JButton("New Model");
136-
btn.addActionListener(new ActionListener() {
137135

138-
@Override
139-
public void actionPerformed(ActionEvent e) {
140-
setTableModel(pt = (pt+1)%3);
141-
}
142-
143-
});
144-
btn.setMaximumSize(new Dimension(80,20));
145-
add(btn);
136+
JButton btn = new JButton("New Model");
137+
btn.addActionListener((e) -> {
138+
setTableModel(pt = (pt + 1) % 3);
139+
});
140+
btn.setMaximumSize(new Dimension(80, 20));
141+
add(btn);
142+
btn = new JButton("Scroll to top");
143+
btn.addActionListener((e) -> {
144+
table.scrollRectToVisible(new Rectangle(0, 0, 10, 10));
145+
});
146+
btn.setMaximumSize(new Dimension(80, 20));
147+
add(btn);
148+
btn = new JButton("Scroll to bottom");
149+
btn.addActionListener((e) -> {
150+
table.scrollRectToVisible(new Rectangle(0, 10600, 10, 10));
151+
});
152+
btn.setMaximumSize(new Dimension(80, 20));
153+
add(btn);
154+
146155
}
147156

148157
int pt = 0;

0 commit comments

Comments
 (0)