|
36 | 36 | import java.awt.Dimension; |
37 | 37 | import java.awt.Graphics; |
38 | 38 | import java.awt.GridLayout; |
| 39 | +import java.awt.Rectangle; |
39 | 40 | import java.awt.event.ActionEvent; |
40 | 41 | import java.awt.event.ActionListener; |
41 | 42 | import java.awt.event.MouseEvent; |
@@ -102,47 +103,55 @@ public void paint(Graphics g) { |
102 | 103 |
|
103 | 104 | public TableDemo() { |
104 | 105 | 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) { |
109 | 111 | // try { throw new NullPointerException();}catch (Exception e) {e.printStackTrace();} |
110 | 112 | // System.err.println("TableDemoUI g.clip=" + g.getClipBounds()); |
111 | | - super.paint(g, c); |
112 | | - |
113 | | - } |
114 | | - |
115 | | - }); |
| 113 | + super.paint(g, c); |
116 | 114 |
|
| 115 | + } |
| 116 | + |
| 117 | + }); |
117 | 118 |
|
118 | 119 | table.setRowHeight(40); |
119 | | - //table.setRowHeight(16); |
120 | | - //table.setRowMargin(1); |
| 120 | + // table.setRowHeight(16); |
| 121 | + // table.setRowMargin(1); |
121 | 122 | table.setPreferredScrollableViewportSize(new Dimension(500, 300)); |
122 | 123 | table.setFillsViewportHeight(true); |
123 | 124 |
|
124 | | - table.setDefaultRenderer(DemoColor.class, new ColorRenderer()); |
| 125 | + table.setDefaultRenderer(DemoColor.class, new ColorRenderer()); |
| 126 | + |
| 127 | + table.setSize(600, 200); |
| 128 | + setTableModel(0); |
125 | 129 |
|
126 | | - table.setSize(600,200); |
127 | | - setTableModel(0); |
128 | | - |
129 | 130 | // Create the scroll pane and add the table to it. |
130 | 131 | JScrollPane scrollPane = new JScrollPane(table); |
131 | 132 |
|
132 | 133 | // Add the scroll pane to this panel. |
133 | 134 | add(scrollPane); |
134 | | - |
135 | | - JButton btn = new JButton("New Model"); |
136 | | - btn.addActionListener(new ActionListener() { |
137 | 135 |
|
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 | + |
146 | 155 | } |
147 | 156 |
|
148 | 157 | int pt = 0; |
|
0 commit comments