Link to home
Start Free TrialLog in
Avatar of wnchui
wnchui

asked on

Disable a particular cell in JTable

How to disable a particular cell in JTable.
I use the code below to add JComboBox to JTable.
          testColumn = JTable1.getColumnModel().getColumn(1);
          JComboBox comboBox = new JComboBox();
        comboBox.addItem("1");
        comboBox.addItem("2");
        comboBox.addItem("3");
        comboBox.addItem("4");
        comboBox.addItem("5");
        comboBox.addItem("None");
        testColumn.setCellEditor(new DefaultCellEditor(comboBox));

Then, how to add different items to different comboBox in JTable.
Avatar of expertmb
expertmb

hi,

use   the property isCellEditable();

mb...
Hi,

Use this method inthe interface  TableCellEditor

public Component getTableCellEditorComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             int row,
                                             int column)


Use the component returned to disable it..

Try it...
ASKER CERTIFIED SOLUTION
Avatar of shaveri
shaveri

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,
 visit this,i think this will solve ur problem

http://forum.java.sun.com/forum?13@40.YLRza9Udkwq^0@.eeec9e9/0

good luck ...

mb...
Avatar of wnchui

ASKER

I try to use this method:

class UneditableJTable extends JTable
{
    public boolean isCellEditable(int row, int column)  
    {
        return false;
    }
}

and then,

UneditableJTable JTable1 = new UneditableJTable();

and JTable1.isCellEditable(1, 1);

but, it will disable all the cell in JTable, how can I disable particular cell?
Avatar of wnchui

ASKER

how can I disable particular cells in run time?