Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ButtonEditor extends DefaultCellEditor {
- protected JButton button;
- private String label;
- private boolean isPushed;
- public ButtonEditor(JCheckBox checkBox) {
- super(checkBox);
- button = new JButton();
- button.setOpaque(true);
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- fireEditingStopped();
- }
- });
- }
- public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
- if (isSelected) {
- button.setForeground(table.getSelectionForeground());
- button.setBackground(table.getSelectionBackground());
- } else {
- button.setForeground(table.getForeground());
- button.setBackground(table.getBackground());
- }
- label = (value == null) ? "Edit" : value.toString();
- button.setText(label);
- isPushed = true;
- return button;
- }
- public Object getCellEditorValue() {
- if (isPushed) {
- /* setEnableEditItemPanel(true);
- itemCodeTextField.setText(String.valueOf(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemCodeColumn)));
- itemCodeTextField.setText(String.valueOf(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemCodeColumn)));
- itemDescriptionTextField.setText(String.valueOf(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemDescriptionColumn)));
- itemPriceTextField.setText(String.valueOf(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemPriceColumn)));
- itemQuantitySpinner.setValue(Integer.parseInt(String.valueOf(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemQuantityColumn))));
- itemSectionSpinner.setValue(inventoryTable.getValueAt(inventoryTable.getSelectedRow(), itemSectionColumn));*/
- }
- isPushed = false;
- return new String(label);
- }
- public boolean stopCellEditing() {
- isPushed = false;
- return super.stopCellEditing();
- }
- protected void fireEditingStopped() {
- super.fireEditingStopped();
- }
- }
- public class ButtonRenderer extends JButton implements TableCellRenderer {
- public ButtonRenderer() {
- setOpaque(true);
- }
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- if (isSelected) {
- setForeground(table.getSelectionForeground());
- setBackground(table.getSelectionBackground());
- } else {
- setForeground(table.getForeground());
- setBackground(UIManager.getColor("Button.background"));
- }
- setText("Edit");
- return this;
- }
- }
Add Comment
Please, Sign In to add comment