• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable

 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 7 colums in a JTable.
I want the first 6 to be uneditable and the last to be editable.

How do you do this with a JTable?

I had to extend it to get the functionality but I'm sure there must ba an easier way.

class MyJTable extends JTable {
MyJTable(String[][] data, String[] columnNames) {
super(data, columnNames);
}

public boolean isCellEditable(int row, int col) {
if (col < 6) {
return false;
} else {
return true;
}
}
}
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For that type of behavior you would want to create your own table model. For such a little change you could probably do it in an anonymous inner class that subclasses DefaultTableModel.

If you want more control over the model you can create a subclass of AbstractTableModel, which is not to difficult. The main advantage I see with AbstractTableModel vs DefaultTableModel is picking your own storage. DefaultTableModel uses a Vector, which is fine for most small/medium tables.

Sun has a tutorial on building table models here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic