DefaultTableModel model = new DefaultTableModel(6,7){ public boolean isCellEditable(int row, int column) { return false; } };In the example above, I'm creating a DefaultTableModel model that has 6 rows and 7 columns. I'm overriding the isCellEditable() method, the method used by other methods and classes to know whether or not a JTable cell can be edited, and returning a boolean value of false in all cases. I could have also returned false for only selected rows and columns by adding conditional logic .
Wednesday, February 21, 2007
Making a JTable Non Editable
There are times when you want to display a JTable in your Swing app, but do not want to the user to be able to edit the cells. Here's a simple way to accomplish this task via the DefaultTableModel:
Subscribe to:
Post Comments (Atom)
8 comments:
Great! It was difficult to find such an elegant solution...
Wow! Kudos to you! All other posts were about making a table renderer which is a complicated answer to a simple problem. But this takes the cake! Great job! =)
Thank you very much
Great solutions are usually simple.
Thanks for posting this example!
you are great! very simple solution. Other people recommends going through tutorials.... Hello? we have already gone through not-so informational tutorials!
Glad you like this solution. I'm a simple guy and I don't like complicated solutions to simple problems.
I am from India. I really liked your solution; simple, elegant and logical. Can you tell me how to make the text in a row, wrap around in the table itself rather than going out of the panel, so that a next row is automatically formed when text exceeds the width of a row.
That's perfect ;p
Thanks man!!!
You save me .รต/
Post a Comment