-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJButtonTableModel.java
More file actions
94 lines (76 loc) · 2.16 KB
/
JButtonTableModel.java
File metadata and controls
94 lines (76 loc) · 2.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.util.*;
import java.awt.BorderLayout;
import javax.swing.*;
public class JButtonTableModel extends RowTableModel<JButton>
{
private static String[] COLUMN_NAMES =
{
"Text",
"Tool Tip Text",
"Enabled",
"Visible"
};
JButtonTableModel()
{
super( Arrays.asList(COLUMN_NAMES) );
setRowClass( JButton.class );
setColumnClass(2, Boolean.class);
setColumnClass(3, Boolean.class);
}
@Override
public Object getValueAt(int row, int column)
{
JButton button = getRow(row);
switch (column)
{
case 0: return button.getText();
case 1: return button.getToolTipText();
case 2: return button.isEnabled();
case 3: return button.isVisible();
default: return null;
}
}
@Override
public void setValueAt(Object value, int row, int column)
{
JButton button = getRow(row);
switch (column)
{
case 0: button.setText((String)value); break;
case 1: button.setToolTipText((String)value); break;
case 2: button.setEnabled((Boolean)value); break;
case 3: button.setVisible((Boolean)value); break;
}
fireTableCellUpdated(row, column);
}
public static void main(String[] args)
{
JButton one = new JButton("One");
JButton two = new JButton("Two");
JButton three = new JButton("Three");
// Use the custom model
JButtonTableModel model = new JButtonTableModel();
// Use the BeanTableModel
// BeanTableModel<JButton> model =
// new BeanTableModel<JButton>(JButton.class, java.awt.Component.class);
model.addRow(one);
model.addRow(two);
model.addRow(three);
JTable table = new JTable(model);
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
JScrollPane scrollPane = new JScrollPane( table );
JPanel south = new JPanel();
south.add(one);
south.add(two);
south.add(three);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.getContentPane().add( scrollPane );
frame.getContentPane().add( south, BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
JButton first = model.getRow(0);
System.out.println(first);
}
}