Single JTable Column with several diff Cell Editors

Am trying to create a single JTable column that can have several different cell editors. Java seems to be bias to having 1 cell editor for the whole column.

For example in 1 column can I have

Row1 : TextBox

Row2: Check Box

Row3: Radio Buttons

Row4: JColorChooser

......

At the moment I can only have one CellEditor for the whole column which is not very helpful.

[427 byte] By [contactnkm] at [2007-9-26 18:24:33]
# 1

the default implementation offers to provide editors per column in the tableColumn and/or editors per class type by setting default editors ( JTable.setDefaultEditor(Class class, TableCellEditor editor) ). If you look at the getCellEditor method of JTable you see that first the tablecolumns are asked for an editor, and if this doesnt succeed a default editor for the class acording to the value at the passed grid position is determined.

If this does not fullfil your needs, you can still overwrite the getCellEditor method of JTable and return whatever editor is suitable.

regards,

stefan

sn.schulz at 2007-7-3 2:33:53 > top of Java-index,Archived Forums,Swing...
# 2

Consider these hints and let me know if I can help U any further:

1)Extend JTable

2)setSelectionMode ListSelectionModel.SINGLE_SELECTION

3) implement getCellRenderer(row,column):

columnClass = getModel().getColumnClass(row)

return getDefaultRenderer(columnClass)

4) implement getCellEditor(self,row,column):

row = getSelectedRow()

columnClass = getModel().getColumnClass(row)

return getDefaultEditor(columnClass)

chainlu at 2007-7-3 2:33:53 > top of Java-index,Archived Forums,Swing...
# 3

Try this;

public class MyTable extends JTable {

public TableCellRenderer getCellRenderer(int row, int col) {

Object o = getModel().getValueAt(row, col);

return getDefaultRenderer(o.getClass());

}

}

your tablemodel's getValueAt

must return an object type that maches the cell renderer setup with setDefaultRenderer(Class,yourcellrenderer)

hinnerdal at 2007-7-3 2:33:53 > top of Java-index,Archived Forums,Swing...
# 4
eg, http://www.geocities.com/rmlchan/mt.html
mchan0 at 2007-7-3 2:33:53 > top of Java-index,Archived Forums,Swing...