Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two questions about columns in JTable  RSS feed

 
Jude Fawly
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1- How can i make two columns of JTable uneditable while others editable?

2- if i have 10 rows in a JTable with data and i deleted data from the second column, how can i move the remaining rows up(no empty row between rows)?
 
Nigel Browne
Ranch Hand
Posts: 703
 
Jude Fawly
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nigel, i am happy with the second link. But still i couldn't solve my problem with the first link. Still i can't make some columns in the JTable editable while others uneditable. Maybe i am stupid. Can you help me please?



-------------------------------------------------------
the code from the link:

// Create a JTable that disallow edits
JTable table1 = new JTable() {
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
};

// Create a JTable based on the same model as table1 but allows edits
JTable table2 = new JTable(table1.getModel());

// Create a model that disallows edits; JTable's using this model will not allow edits
TableModel model = new DefaultTableModel() {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
---------------------------------------------------------------------------
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must make each cell in the column uneditable. You can achieve this by looping through the cells and using the overridden isCellEditable(int, int) method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!