Hi I have a problem with my JTable and I need your help. Problem: I have a JTable with 4 columns ( Col A, Col B, Col C and Col D). Under the JTable I have 3 checkboxes(Col 1, Col 2, Col 3). The user can add a new column to the JTable by choosing one of these checkboxes.I want that when the user choose one of check boxes, the new column will be place before Col D. Meaning that Col D will be always the last column in table.How can I do this??? my code: TableColumnModel model = resultTable.getColumnModel();
JLabel checkBoxLabel = new QCLabel("Cols: "); JCheckBox col1 = new QCCheckBox("Col 1"); JCheckBox col2 = new QCCheckBox("Col2"); JCheckBox col3 = new QCCheckBox("Col3");
Either use moveColumn() as Eddie suggested or create your own implementation of TableModel, e.g. by extending DefaultTableModel. does that help? D.
Joined: Feb 23, 2004
Hi D I have created my own implementation of TableModel.But I don't no how to do that.You see I am new in Java and every thing is new for me.Can you help me litle bit more. Thanks
Joined: Dec 12, 2002
To make one column always appear at the end you have to code the getColumnName, getValueAt, setValueAt and isCellEditable methods accordingly. If you've never created your own TableModel before read this Post your code, lets have a look at what you've done. D.
Welcome to the Ranch c ca Please take a look at ournaming policy and adjust your displayed name accordingly. If you are new to Java relax, JTable has one the most elaborated API in the whole Swing. Thus it needs to be tackled step to step. Please read How to use Tables in the Java Tutorial. Read it twice at least, Write short examples to thrive your knowledge. Write examples before asking here. Read the API before writting examples. Many doubts can be cleared in this way. Please ident your code using UBB Code and be very specific in your questions. In the excellent book Swing by Vorobiev and Robinson you can find an example of Column addition and removal [ March 01, 2004: Message edited by: Jose Botella ] [ March 01, 2004: Message edited by: Jose Botella ]