| 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 |
package dr.app.bss; |
| 27 |
|
| 28 |
import java.awt.Component; |
| 29 |
import java.awt.event.ActionEvent; |
| 30 |
import java.awt.event.ActionListener; |
| 31 |
|
| 32 |
import javax.swing.DefaultCellEditor; |
| 33 |
import javax.swing.JButton; |
| 34 |
import javax.swing.JCheckBox; |
| 35 |
import javax.swing.JTable; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
@SuppressWarnings("serial") |
| 42 |
public class JTableButtonCellEditor extends DefaultCellEditor { |
| 43 |
|
| 44 |
protected JButton button; |
| 45 |
private String label; |
| 46 |
private boolean isPushed; |
| 47 |
|
| 48 |
public JTableButtonCellEditor() { |
| 49 |
|
| 50 |
super(new JCheckBox()); |
| 51 |
|
| 52 |
button = new JButton(); |
| 53 |
button.setOpaque(true); |
| 54 |
button.addActionListener(new ActionListener() { |
| 55 |
public void actionPerformed(ActionEvent e) { |
| 56 |
fireEditingStopped(); |
| 57 |
} |
| 58 |
}); |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
public Component getTableCellEditorComponent(JTable table, |
| 63 |
Object value, boolean isSelected, int row, int column) { |
| 64 |
|
| 65 |
if (isSelected) { |
| 66 |
button.setForeground(table.getSelectionForeground()); |
| 67 |
button.setBackground(table.getSelectionBackground()); |
| 68 |
} else { |
| 69 |
button.setForeground(table.getForeground()); |
| 70 |
button.setBackground(table.getBackground()); |
| 71 |
} |
| 72 |
|
| 73 |
label = (value == null) ? "" : value.toString(); |
| 74 |
button.setText(label); |
| 75 |
isPushed = true; |
| 76 |
|
| 77 |
return button; |
| 78 |
} |
| 79 |
|
| 80 |
public Object getCellEditorValue() { |
| 81 |
if (isPushed) { |
| 82 |
|
| 83 |
} |
| 84 |
isPushed = false; |
| 85 |
return new String(label); |
| 86 |
} |
| 87 |
|
| 88 |
public boolean stopCellEditing() { |
| 89 |
isPushed = false; |
| 90 |
return super.stopCellEditing(); |
| 91 |
} |
| 92 |
|
| 93 |
protected void fireEditingStopped() { |
| 94 |
super.fireEditingStopped(); |
| 95 |
} |
| 96 |
|
| 97 |
} |