Class ButtonColumn

java.lang.Object
javax.swing.AbstractCellEditor
org.jjazz.uiutilities.api.ButtonColumn
All Implemented Interfaces:
ActionListener, MouseListener, Serializable, EventListener, CellEditor, TableCellEditor, TableCellRenderer

public class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener
The ButtonColumn class provides a renderer and an editor that looks like a JButton. The renderer and editor will then be used for a specified column in the table. The TableModel will contain the String to be displayed on the button.

The button can be invoked by a mouse click or by pressing the space bar when the cell has focus. Optionaly a mnemonic can be set to invoke the button. When the button is invoked the provided Action is invoked. The source of the Action will be the table. The action command will contain the model row number of the button that was clicked.

Author: Rob Camick from https://tips4java.wordpress.com/2009/07/12/table-button-column/

See Also:
  • Constructor Details

    • ButtonColumn

      public ButtonColumn(JTable table, ActionListener al, int column)
      Create the ButtonColumn to be used as a renderer and editor. The renderer and editor will automatically be installed on the TableColumn of the specified column.
      Parameters:
      table - the table containing the button renderer/editor
      al - the Action to be invoked when the button is invoked
      column - the column to which the button renderer/editor is added
  • Method Details

    • getFocusBorder

      public Border getFocusBorder()
      Get foreground color of the button when the cell has focus
      Returns:
      the foreground color
    • setFocusBorder

      public void setFocusBorder(Border focusBorder)
      The foreground color of the button when the cell has focus
      Parameters:
      focusBorder - the foreground color
    • getMnemonic

      public int getMnemonic()
    • setMnemonic

      public void setMnemonic(int mnemonic)
      The mnemonic to activate the button when the cell has focus
      Parameters:
      mnemonic - the mnemonic
    • getTableCellEditorComponent

      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
      Specified by:
      getTableCellEditorComponent in interface TableCellEditor
    • getCellEditorValue

      public Object getCellEditorValue()
      Specified by:
      getCellEditorValue in interface CellEditor
    • getTableCellRendererComponent

      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      The button has been pressed. Stop editing and invoke the custom Action
      Specified by:
      actionPerformed in interface ActionListener
    • mousePressed

      public void mousePressed(MouseEvent e)
      When the mouse is pressed the editor is invoked. If you then then drag the mouse to another cell before releasing it, the editor is still active. Make sure editing is stopped when the mouse is released.
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener