Testing and coding for hours with the help of the web sites of Swing
connection
and Java Tutorial, I didn't managed to get a stupid simple JButton in a
JTable.
Well, I somehow got it into there (with own ButtonRenderer and
ButtonEditor)
but clicking/double clicking a button cell doesn't do anything! It
doesn't fire its
action command!
I just want to have a column of class JButton to be each cell a JButton
with a specific
text. Because the cell object data id of class JButton and the table
displays a (white)
button with the correct title, I assume to do it right. So, how can I
get the button to
fire its action command? I tried it with myTable.setDefault
renderer/editor by defining
my own ones.
Any ideas? Is the solution completely different?
Martin
/**
* Command Column Cell Editor
*
* @author Paolo Vedovato
* @version $Revision: 1.4 $, $Date: Sep 14 1998 13:48:26
$
*/
class CommandColumnEditor extends DefaultCellEditor
{
/*
* I extend DefaultCellEditor for convenience,
* even though it mean we have to create a dummy
* check box. Another approach would be to copy
* the implementation of TableCellEditor methods
* from the source code for DefaultCellEditor.
*/
public CommandColumnEditor(JCheckBox checkBox)
{
super(checkBox);
}
}
/**
* Action Command Column Cell Editor
*
* @author Paolo Vedovato
* @version $Revision: 1.0 $, $Date: Sep 14 1998 13:49:10
$
*/
class PreListenCommandEditor extends CommandColumnEditor
{
private JButton button = new JButton();
private AudioEngineServer audioEngineServer;
private MediaGatewayIf mediaGatewayServer;
private String cmdLabel;
public PreListenCommandEditor(String cmd, ImageIcon icon, CorbaInterface
ci)
{
super(new JCheckBox());
editorComponent = button;
// start editor after on click
setClickCountToStart(1);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "Action! :-)");
fireEditingStopped();
}
});
}
public Component getTableCellEditorComponent( JTable table,
Object value,
boolean isSelected,
int row,
int column)
{
table.setRowSelectionInterval(row,row);
return editorComponent;
}
public Object getCellEditorValue()
{
return null;
}
protected void fireEditingStopped()
{
super.fireEditingStopped();
}
Greetings
Paolo
Martin Hilpert wrote in message <35FEC02C...@framesoft.de>...
Your email (p.ved...@iname.com) doesn't work!
Thanks again!
Martin :-)
why is the code not working? it does the job perfectly for me. the interface
funtion actionPerformed() is implemented in the instantiation of the
ActionListener()...
thanks for the notice that my email doesn't work -> now its fixed!
see ya in the kawa newsgroups ;-)
paolo
Martin Hilpert wrote in message <35FF872B...@framesoft.de>...