you probably want a button--> you need to use a button as the renderer,
and also use a button as an editor; then it will look pressed and
respond to clicks.
so, make a JTable extension and for that column return an Editor whose
getTableCellEditorComponent() method returns a button.
then, put an actionlistener on that button, and inside the
actionlistener call the getEditingrow() to find out which row of the
table the button is on, and then do the right thing:
btw- TestConnectionButton is a class that Extends JButton;which also
happens to implement the TableCellRenderer interface as well.
search this group for putting JButtons into tables; and you may want to
have each "label" be a button in it's own column; you can make the
table not draw its gridlines if you want.
hope this helps
-Jill
/***********************************************************************
*The ButtonEditor; this is what makes the Button be pressable
*and it has an actionlistener, so that when the button is pressed
*it executes the testConnection method on the correct row
***********************************************************************/
public class ButtonEditor extends AbstractCellEditor
implements TableCellEditor, ActionListener {
private TestConnectionButton m_editor;
public ButtonEditor()
{
m_editor = new TestConnectionButton();
m_editor.setContentAreaFilled(true);
m_editor.addActionListener(this);
}
public JButton editor(){
return m_editor;
}
public void actionPerformed(ActionEvent e){
Debug.Print("clicked the button: status: "+ m_editor.getText());
int row = getEditingRow();
Debug.Print("current row: "+row);
ConnectionTableModel ctm =
(ConnectionTableModel)getModel();
ConnectionDesc lineItem = ctm.getItemAt(row);
String details = lineItem.getDescription();
if(StringUtils.isBlank(details)){
//don't do the action; put in a msg to the user
MessageDialog.showMessage("Connection needs a value to be tested",
m_editor);
Debug.Print("\n\n********don't**********");
} else {
Debug.Print("got the ctm: "+ ctm);
if (!(lineItem.statusTestAble())){
MessageDialog.showMessage("Connection already Tested",m_editor);
} else {
boolean okay = ctm.testConnection(row);
m_editor.setLF(okay);
}
}
}
public Component getTableCellEditorComponent(JTable table,
Object value,
boolean selected,
int row,
int column) {
ConnectionTableModel ctm = (ConnectionTableModel)table.getModel();
ConnectionDesc connection = ctm.getItemAt(row);
int status = connection.getStatus();
m_editor.setLF(status);
m_editor.setForeground(table.getForeground());
return m_editor;
}
public Object getCellEditorValue(){
return m_editor.getText();
}
} //end button Editor class