Monday, February 26, 2007
Exporting JTable data to Excel Revised
Someone alerted me to a problem with my JTable exporting example. It seems with all the changes I've been making to my blog, I lost some of the code at the end of the example. It's been restored and can be found here: Tech Thoughts: Exporting JTable data to Excel.
Rick.
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:
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 .
Friday, February 09, 2007
I love Simple Solutions
While developing a a JTree TreeModel built from a MySQL database (I'll post an example later), I found the following simple approach for expanding all the nodes at once:
for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); // tree is your JTree component }Thanks Javalobby for providing this example.
Subscribe to:
Posts (Atom)