PropertyEditor adapter

How might I use an existing java.beans.PropertyEditor implementation as a TableCellEditor in a JTable? I have been attempting to wrap the PropertyEditor in a TableCellEditor implementor, then delegating TableCellEditor.getTableCellEditorComponent() to return PropertyEditor.getCustomEditor(). Is the approach flawed? Is there a better way?

[346 byte] By [developer_jbsa] at [2007-11-27 3:18:05]
# 1

Point value is up.

Here is the adapter I am trying to use...

public class PropertyEditorAdapter extends AbstractCellEditor

implements TableCellEditor, TableCellRenderer {

private PropertyEditor myPropertyEditor;

private PropertyEditorAdapter() {}

public PropertyEditorAdapter( PropertyEditor pe ) {

this();

myPropertyEditor = pe;

}

//////////////////////////////////////////////////////////////////////////////

// TableCellEditor impl

//

public Component getTableCellEditorComponent(

JTable table,

Object value,

boolean isSelected,

int row,

int column ) {

if( myPropertyEditor == null ) {

return new JLabel( value==null ? "" : value.toString() );

} else {

myPropertyEditor.setValue( value );

return myPropertyEditor.getCustomEditor();

}

}

//

// TableCellEditor impl

//////////////////////////////////////////////////////////////////////////////

// TableCellRenderer impl

//

public Component getTableCellRendererComponent(

JTable table,

Object value,

boolean isSelected,

boolean hasFocus,

int row,

int column ) {

if( myPropertyEditor == null ) {

return new JLabel( value==null ? "" : value.toString() );

} else {

myPropertyEditor.setValue( value );

return myPropertyEditor.getCustomEditor();

}

}

//

// TableCellRenderer impl

//////////////////////////////////////////////////////////////////////////////

public Object getCellEditorValue() {

return myPropertyEditor.getValue();

}

}

developer_jbsa at 2007-7-12 8:20:42 > top of Java-index,Desktop,Developing for the Desktop...