This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making JTable Non - Editable

 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Nathan its been a long time since i wrote to you, and i hope you arent missing any of your last trains to your home. Coming to business,
I would like to display a ResultSet in a JTable. How do i make the JTbale Non-Editable.
Secondly the JTable does not get repainted/refreshed when i display the next ResultSet rather it is overlapped on the earlier displayed data.
A sample code will be more appreciated.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create your own table model and return false in the isCellEditable().
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the code related to the table that you already have? It is easier to just fix what is wrong and not worry about the rest of the things you already have that work.

Paul is right about overriding isCellEditable() to make your table non-editable... it sounds like the other problem you are having is due to either update problems, or problems with the renderers you are using for your table... without seeing code I am not sure which...

-Nate
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vaskar,
Once you have your DataModel up and running ypou can stick in the methods you need to update the table the way you like.
Your DataModel class should have a Vector of Vectors for data to allow you to add and remove data freely.
Your data modification methods just modify the DataModel's data Vector according to your needs and then invoke a fireTableXXXChanged() call on the tablemodel to force the revalidating of the relevant cells - there are several of these to allow you to update parts or all the data as needed.
Hope that helps,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic