I have created a customized editor for my table by extending default editor in java. The code look like
import java.awt.Component;
import java.text.ChoiceFormat;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JTable;
import com.ushustech.nmsazzist.model.mib.MibVariableModel;
public class MibFormattedValueEditor extends DefaultCellEditor
{
private JComboBox m_comboBox;
public MibFormattedValueEditor()
{
this(new JComboBox());
}
public MibFormattedValueEditor(JComboBox comboBox)
{
super(comboBox);
this.m_comboBox = comboBox;
}
@Override
public Object getCellEditorValue()
{
return this.m_comboBox.getSelectedItem();
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
this.m_comboBox.removeAllItems();
MibVariableModel model = (MibVariableModel) table.getModel();
ChoiceFormat format = model.getMibVariable(row).getFormat();
if(null != format){
Object[] obj = format.getFormats();
for(int i=0;i<obj.length;i++){
this.m_comboBox.addItem(obj[i].toString());
}
}
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
}
I want to display a text field editor if the format is null ? Please Help me for doing this? Thanks.
I wouldn’t replace the
ComboBoxas this can get dirty. I would rather set it editable in case offormat == nulland let the user input the information here. Like this: