• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Selecting cells in JTable

 
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1973
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic