-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableCellRenderFrame.java
More file actions
44 lines (33 loc) · 1.29 KB
/
TableCellRenderFrame.java
File metadata and controls
44 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tableCellRender;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* This frame contains a table of planet data.
*/
public class TableCellRenderFrame extends JFrame
{
private static final int DEFAULT_WIDTH = 600;
private static final int DEFAULT_HEIGHT = 400;
public TableCellRenderFrame()
{
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
TableModel model = new PlanetTableModel();
JTable table = new JTable(model);
table.setRowSelectionAllowed(false);
// set up renderers and editors
table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
table.setDefaultEditor(Color.class, new ColorTableCellEditor());
JComboBox<Integer> moonCombo = new JComboBox<>();
for (int i = 0; i <= 20; i++)
moonCombo.addItem(i);
TableColumnModel columnModel = table.getColumnModel();
TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif")));
// show table
table.setRowHeight(100);
add(new JScrollPane(table), BorderLayout.CENTER);
}
}