JTable Help
Hi, I am having an issue with my JTable i hope someone can help me out on.
I have a JTable with 10 columns. The user has an option on the JMenuBar to hide columns 5,6,7 and 8. To do this i use the Menu Listener:
if(e.getSource()== hideColumns)
{
TableColumnModel columnModel1 = list.getColumnModel();
if (hideColumns.isSelected())
{
columnModel1.removeColumn( columnModel1.getColumn( 8 ) );
columnModel1.removeColumn( columnModel1.getColumn( 7 ) );
columnModel1.removeColumn( columnModel1.getColumn( 6 ) );
columnModel1.removeColumn( columnModel1.getColumn( 5 ) );
}
That works fine. But my issue comes when i want to bring those columns back. The rest of the listener goes as follows:
elseif (!(hideColumns.isSelected()))
{
TableColumn fareCol=new TableColumn();
TableColumn paidCol=new TableColumn();
TableColumn checkCol=new TableColumn();
TableColumn chargeCol=new TableColumn();
fareCol.setHeaderValue("Fare");
paidCol.setHeaderValue("Paid");
checkCol.setHeaderValue("Check");
chargeCol.setHeaderValue("Charge");
columnModel1.addColumn(fareCol);
columnModel1.addColumn(paidCol);
columnModel1.addColumn(checkCol);
columnModel1.addColumn(chargeCol);
columnModel1.moveColumn(5,9);
}
This second part of the listener creates 4 new columns, assigns headers to them, and places them on the end of the table. The last line moves what used to be Column 10, back to the end. This results in the columns ending back up in the correct order.
When i run the program, data gets entered into the table just fine. All of the columns populate correctly etc. I activate the menu control, make the columns disappear, data still is correct. Only columns 1,2,3,4,5, and 10 show, and the data in them is correct.
When i activate the menu control again, to make the columns reappear, the columns reappear, but they only show data that is in the first column.
First off, is there a more effiecient way of doing what I'm trying to do? If not, how would i fix the problem i'm having?
*** Note, i'm sort of a n00b stumbling through this program. You may have to be a bit detailed. Thanks **

