-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathColorTableCellEditor.java
More file actions
69 lines (58 loc) · 1.76 KB
/
Copy pathColorTableCellEditor.java
File metadata and controls
69 lines (58 loc) · 1.76 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
package tableCellRender;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* This editor pops up a color dialog to edit a cell value.
*/
public class ColorTableCellEditor extends AbstractCellEditor implements TableCellEditor
{
private JColorChooser colorChooser;
private JDialog colorDialog;
private JPanel panel;
public ColorTableCellEditor()
{
panel = new JPanel();
// prepare color dialog
colorChooser = new JColorChooser();
colorDialog = JColorChooser.createDialog(null, "Planet Color", false, colorChooser,
EventHandler.create(ActionListener.class, this, "stopCellEditing"),
EventHandler.create(ActionListener.class, this, "cancelCellEditing"));
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int row, int column)
{
// this is where we get the current Color value. We store it in the dialog in case the user.
// starts editing
colorChooser.setColor((Color) value);
return panel;
}
public boolean shouldSelectCell(EventObject anEvent)
{
// start editing
colorDialog.setVisible(true);
// tell caller it is ok to select this cell
return true;
}
public void cancelCellEditing()
{
// editing is canceled--hide dialog
colorDialog.setVisible(false);
super.cancelCellEditing();
}
public boolean stopCellEditing()
{
// editing is complete--hide dialog
colorDialog.setVisible(false);
super.stopCellEditing();
// tell caller is is ok to use color value
return true;
}
public Object getCellEditorValue()
{
return colorChooser.getColor();
}
}