Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable CellRenderer/Editor: button in a JTable?

132 views
Skip to first unread message

Martin Hilpert

unread,
Sep 15, 1998, 3:00:00 AM9/15/98
to
Hi!

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

Paolo V.

unread,
Sep 16, 1998, 3:00:00 AM9/16/98
to
i see that you made the cell renderer now try following cell editor ...

/**
* 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>...

Martin Hilpert

unread,
Sep 16, 1998, 3:00:00 AM9/16/98
to
Thanks for your help, Paolo! The code didn't work completely
(e.g. new ActionListener() doesn't work because it's an interface),
but I got the idea how to do it.

Your email (p.ved...@iname.com) doesn't work!

Thanks again!
Martin :-)


Paolo V.

unread,
Sep 18, 1998, 3:00:00 AM9/18/98
to
hi 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>...

0 new messages