Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

About KeyEvent?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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!
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!