• Post Reply Bookmark Topic Watch Topic
  • New Topic

Selecting cells in JTable

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a JTable, how do you enable the user to
select a cell, but not edit it?
I've got some preliminary code like below, but
it doesn't stop the user from changing the value
in my 'play' table.
In particular, I thought the setCellSelectionEnabled would keep the cell from being edited but it doesn't appear to.
=================================================
model = new DefaultTableModel();
jTable_MatchedFiles = new JTable(model);
jTable_MatchedFiles.setRowSelectionAllowed(false);
jTable_MatchedFiles.setCellSelectionEnabled(false);
model.addColumn("Directory");
model.addColumn("File Name");
model.addColumn("File Size");
model.addColumn("File Date");
String[] firstRow = {"1", "2", "3", "4"};
model.addRow(firstRow);

===============================================
Thanks for any ideas.
--Mike
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to override the isCellEditable() method in the AbstractTableModel. Here is an example of one I have. The difference with mine is my model takes in Vectors where the AbstractTableModel takes in Object[][] and Strings[].

Notice that the isCellEditable returns false. Hope that helps a little.
[ October 01, 2002: Message edited by: Gregg Bolinger ]
 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!