How to make JTable cell editable/uneditable dynamically
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Srikanth_Telugu
Posted On:   Thursday, May 22, 2008 09:37 AM

Hi, I have created a JTable using AbstractTableModel, Initially second column is uneditable and remaining column cells are editable. When JFrame is set visible, a button and table is displayed with second column uneditable. When a Admin user clicks on button or F2 function key is pressed, a dialog box appears for admin authorization. When he logs in, In the same table which is displayed earlier, the second column which is uneditable has to be made editable dynamically. For other users it should be uneditable. Iam not able to find exact code to make the cell editable at run time. The code i have written to create JTable is as follows. class MyTableModel extends AbstractTableMo   More>>

Hi,

I have created a JTable using AbstractTableModel, Initially second column is uneditable and remaining column cells are editable. When JFrame is set visible, a button and table is displayed with second column uneditable.

When a Admin user clicks on button or F2 function key is pressed, a dialog box appears for admin authorization. When he logs in, In the same table which is displayed earlier, the second column which is uneditable has to be made editable dynamically. For other users it should be uneditable.

Iam not able to find exact code to make the cell editable at run time.



The code i have written to create JTable is as follows.

			
class MyTableModel extends AbstractTableModel {
private String[] columnNames = { "SlNo", "Price", "Product"};

private Object[][] data = {
{ "1", "340", "Camera"},
{ "2", "500", "Mobile"},
{ "3", "400", "Walkman",},
{ "4", "20", "CD"},
{ "5", "100", "DVD"} };

public final Object[] longValues = { "Sharon", "Campione",
"None of the above", new Integer(20), Boolean.TRUE };

public int getColumnCount() {
return columnNames.length;
}

public int getRowCount() {
return data.length;
}

public String getColumnName(int col) {
return columnNames[col];
}

public Object getValueAt(int row, int col) {
return data[row][col];
}

public Class <?> getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

public boolean isCellEditable(int row, int col) {
* if(col==1)*
* return false;*
return true;
}
}




Need Suggestions.


Thanks in advance

Srikanth

   <<Less
About | Sitemap | Contact