• 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

About KeyEvent?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question about KeyEvent: I add a KeyListener to a JTable. To prohibit user modifing the data in JTable, I attempt to capture a KeyEvent and pop up a warning message when an user types keyboard to modify some data in JTable. I hope whatever user type which key the warning message would pop up and stop the modifing. How to do that???
My code was show bellow:
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richard,
Try to find out some posts on AbstractTableModel. I doubt if you are using it. You can define your JTable using the constructor.
JTable table = new JTable(new MyTableModel());
where MyTableModel class extends AbstractTableModel. Define a method named
public boolean isEditable(int row, int col) {
return false;
}
in the MyTableModel class. This will prevent the user from modifying your JTable.
Hope it helps
 
Richard Phen
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishal Sinha,
Thank you for your quick and clear reply! Yes, Your answer is very valuable to me!
I modified my code and achieved the goal.
class MyTableModel extends DefaultTableModel
{
......
public boolean isCellEditable(int row, int column)
{
return false;
}
}
Thank you again!
reply
    Bookmark Topic Watch Topic
  • New Topic