Amigo, estou com um problema, busquei conhecimento e li bastante a cerca do tema de adicionar componentes na JTable, porém ocorre que quando altero o valor da combo no primeiro item, ele altera de todas as demais logo abaixo, porém se altero somente as abaixo da primeira o comportamento fica como desejado, sabem se posso estar realizando algo de maneira incorreta?
Abraços a todos, segue o código abaixo para apreciação :
tblFile = new JTable(getModelFile());
ImportLayoutConstComboBoxColumn importLayoutConstComboBoxColumn = new ImportLayoutConstComboBoxColumn(tblFile);
tblFile.getColumnModel().getColumn(1).setCellRenderer(importLayoutConstComboBoxColumn);
tblFile.getColumnModel().getColumn(1).setCellEditor(importLayoutConstComboBoxColumn);
class ImportLayoutConstComboBoxColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener
{
JTable table;
JComboBox<ImportLayoutConst> renderCombobox;
JComboBox<ImportLayoutConst> editCombobox;
public ImportLayoutConstComboBoxColumn(JTable table)
{
super();
this.table = table;
renderCombobox = new JComboBox<ImportLayoutConst>(ImportLayoutConst.values());
editCombobox = new JComboBox<ImportLayoutConst>(ImportLayoutConst.values());
editCombobox.addActionListener(this);
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
if(value != null)
{
renderCombobox.getModel().setSelectedItem(value);
}
else
{
renderCombobox.setSelectedIndex(-1);
}
return renderCombobox;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
if(value != null)
{
editCombobox.getModel().setSelectedItem(value);
}
return editCombobox;
}
public Object getCellEditorValue()
{
return editCombobox.getSelectedItem();
}
public void actionPerformed(ActionEvent e)
{
((FileImportTableModel) table.getModel()).getObject(table.getSelectedRow()).setLayout((ImportLayoutConst) editCombobox.getSelectedItem());
fireEditingStopped();
}
}