| | |
About JTable
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 14
Reputation:
Solved Threads: 3
hi, i spend many sleeples nights trying to solve it i did it this way:
first create custom table model like this, and ascribe it to the table:
then to remove column from view you do
where columnId is column number from table model
to bring it back
you have to remember about:
its get a little bit more tricky if you want to sort the table too...
first create custom table model like this, and ascribe it to the table:
Java Syntax (Toggle Plain Text)
DefaultTableModel tableModel = new DefaultTableModel(null,new String[]{"Column1", "Column2", "Column3"});
Java Syntax (Toggle Plain Text)
table.removeColumn(table.getColumnModel().getColumn(columnId));
to bring it back
Java Syntax (Toggle Plain Text)
table.addColumn(new TableColumn(columnId));
- repaint() each time you add, remove column
- always remove columns from the last one, because if you have columns 0,1,2,3 and remove column(0) the indexes are recount and you will have columns 0,1,2
- use first if you want to read dataJava Syntax (Toggle Plain Text)
- table.convertColumnIndexToModel(table.getSelectedRow());
- add, change, remove rows should be done on tableModel, not on the table directly
its get a little bit more tricky if you want to sort the table too...
Last edited by arseniew; Feb 2nd, 2009 at 1:44 pm.
•
•
Join Date: Sep 2008
Posts: 1,595
Reputation:
Solved Threads: 200
I think you have to call the revalidate method on your JTable, after removing or adding a column, to make it work. Its been a while, but I think that's the advice Ezzaral gave me when I asked a similar question before (I could be misquoting him; whatever advice he gave me worked).
Last edited by BestJewSinceJC; Feb 3rd, 2009 at 12:45 am.
![]() |
Similar Threads
- Problem changing contents of JTable when button is pressed... (Java)
- deleting rows from a JTable (Java)
- How to make JTable cell not Editable (Java)
- JTable Reloading/Refreshing/Updating/Whatever. (Java)
- Adding and deleting a column in JTable (Java)
- JTable problem (Java)
- Getting horizontal scrollbars in a JTable (Java)
- JTable not calling getValueAt - any ideas? (Java)
- Saving and opeing a JTable (Java)
Other Threads in the Java Forum
- Previous Thread: Can Someone Help?
- Next Thread: Java Coin Purse problem
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working






