quick.dbtable
Interface CellComponent


public interface CellComponent

CellComponent is used to create user defined editor renderer for quicktable.

  Example
  class MyCell implements CellComponent
  {
      JCombobox myCombo = new JCombobox();
      MyCell()
      {
         myCombo.addItem("Alive");
         myCombo.addItem("Dead");
         myCombo.addItem("Leave");
      }

      public void setValue(Object value)
      {
          myCombo.setSelectedItem(value);
          //handle the case if null is passed
      }

      public Object getValue()
      {
  	return myCombo.getSelectedItem();
          //return "" if nothing is selected
      }


      public JComponent getComponent()
      {
         return mycombo;
      }

      public void addActionListener(ActionListener listener)
      {
         mycombo.addActionListener(listener)
      }
  }
  yourQuickTable.getColumn(1).setUserCellEditor(new MyCell());

 

Since:
2.0.2
See Also:
Column.setUserCellEditor(CellComponent), Column.setUserCellRenderer(CellComponent)

Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          If this cell component is a cell editor & if it wants to notify the table that editing is completed, the actionlistener in this method should be notified.
 javax.swing.JComponent getComponent()
          returns the JComponent which is used as the component
 java.lang.Object getValue()
          returns the data from the editor/renederer
 void setValue(java.lang.Object val)
          sets the data to the renderer/editor
 

Method Detail

setValue

public void setValue(java.lang.Object val)
sets the data to the renderer/editor


getValue

public java.lang.Object getValue()
returns the data from the editor/renederer


getComponent

public javax.swing.JComponent getComponent()
returns the JComponent which is used as the component


addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
If this cell component is a cell editor & if it wants to notify the table that editing is completed, the actionlistener in this method should be notified. This method is Optional to implement.
  e.g. If the cell component is a combo box

  public void addActionListener(ActionListener listener)
  {
    yourComboBox.addActionListener(listener)
  }

  So the combo box will notify JTable, whenever the data is changed.

  If the JComponent which you are using in your cellcomponent doesn't have a
  addActionListener method, or if the cell component only fires some other
  type event like itemChanged, then all you have to do is, notify the listener
  whenever there is a change in data using  listener.actionPerformed(null);
  e.g
  class MyCellCompoenent implements CellComponent
  {
     ActionListener listener;

     ...

     public void addActionListener(ActionListener listener)
     {
       this.listener = listener;
     }

     public void valueChangedInMyJComponent()
     {
       listener.actionPerformed( null );
     }

  }