-
October 17th, 2017, 12:06 PM
#16
Re: jtable column blues
here is the code
Code:
for(int col=0;col<=2;col++)
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(1));
It does not remove the last 3 columns
Columns after removal I want showing are : Col 1 | 1 | Col 2 | 34.3 |
| 2 | | 13 |
fixed editable feild
Last edited by Azoth; October 17th, 2017 at 12:17 PM.
-
October 18th, 2017, 02:41 AM
#17
Re: jtable column blues
Originally Posted by Azoth
here is the code
Code:
for(int col=0;col<=2;col++)
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(1));
It does not remove the last 3 columns
Columns after removal I want showing are : Col 1 | 1 | Col 2 | 34.3 |
| 2 | | 13 |
fixed editable feild
I thought you have 7 columns and want to remove columns 2 to 6. That means leaving the first and last columns, which is what you should get with my code sample. But now you say it is not removing the last 3 columns?
Can you please state clearly what you want to do, showing the end state of the table and also the original state?
-
October 18th, 2017, 07:53 AM
#18
Re: jtable column blues
Originally Posted by jcaccia
I thought you have 7 columns and want to remove columns 2 to 6. That means leaving the first and last columns, which is what you should get with my code sample. But now you say it is not removing the last 3 columns?
Can you please state clearly what you want to do, showing the end state of the table and also the original state?
I have a table with 7 columns
Since indexes start at 0;columns go 0-6
So i want col 1 and 4- 6 removed
-
October 18th, 2017, 07:56 AM
#19
Re: jtable column blues
I have a table with 7 columns
Since indexes start at 0,cols go 0-6 .
I want col 2 and cols 4-6 deleted
-
October 18th, 2017, 09:35 AM
#20
Re: jtable column blues
Originally Posted by Azoth
I have a table with 7 columns
Since indexes start at 0,cols go 0-6 .
I want col 2 and cols 4-6 deleted
Ok, this is not exactly the same as
Originally Posted by Azoth
I have a table with 7 columns. I am trying to delete columns 2-6.
or your other post with a sample of what you wanted as a table with apparently just 2 columns.
So, starting with this table:
Code:
| Col 0 | Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
| 1st | 2nd | 3rd | 4th | 5th | 6th | 7th |
do you want to end with this table (2nd, 4th, 5th, and 6th columns removed):
Code:
| Col 0 | Col 2 | Col 6 |
| 1st | 3rd | 7th |
or this one (columns with indexes 2, 4, 5, and 6 removed):
Code:
| Col 0 | Col 1 | Col 3 |
| 1st | 2nd | 4th |
To get the first result use this:
Code:
// remove column at index 1 (2nd)
// | Col 0 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
// | 1st | 3rd | 4th | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(1));
// remove column now at index 2 (4th)
// | Col 0 | Col 2 | Col 4 | Col 5 | Col 6 |
// | 1st | 3rd | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 2 (5th)
// | Col 0 | Col 2 | Col 5 | Col 6 |
// | 1st | 3rd | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 2 (6th)
// | Col 0 | Col 2 | Col 6 |
// | 1st | 3rd | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
For the second option use this:
Code:
// remove column at index 2 (3rd)
// | Col 0 | Col 1 | Col 3 | Col 4 | Col 5 | Col 6 |
// | 1st | 2nd | 4th | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 3 (5th)
// | Col 0 | Col 1 | Col 3 | Col 5 | Col 6 |
// | 1st | 2nd | 4th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
// remove column now at index 3 (6th)
// | Col 0 | Col 1 | Col 3 | Col 6 |
// | 1st | 2nd | 4th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
// remove column now at index 3 (7th)
// | Col 0 | Col 1 | Col 3 |
// | 1st | 2nd | 4th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
-
October 20th, 2017, 07:05 PM
#21
Re: jtable column blues
Originally Posted by jcaccia
Ok, this is not exactly the same asor your other post with a sample of what you wanted as a table with apparently just 2 columns.
So, starting with this table:
Code:
| Col 0 | Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
| 1st | 2nd | 3rd | 4th | 5th | 6th | 7th |
do you want to end with this table (2nd, 4th, 5th, and 6th columns removed):
Code:
| Col 0 | Col 2 | Col 6 |
| 1st | 3rd | 7th |
or this one (columns with indexes 2, 4, 5, and 6 removed):
Code:
| Col 0 | Col 1 | Col 3 |
| 1st | 2nd | 4th |
To get the first result use this:
Code:
// remove column at index 1 (2nd)
// | Col 0 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
// | 1st | 3rd | 4th | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(1));
// remove column now at index 2 (4th)
// | Col 0 | Col 2 | Col 4 | Col 5 | Col 6 |
// | 1st | 3rd | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 2 (5th)
// | Col 0 | Col 2 | Col 5 | Col 6 |
// | 1st | 3rd | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 2 (6th)
// | Col 0 | Col 2 | Col 6 |
// | 1st | 3rd | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
For the second option use this:
Code:
// remove column at index 2 (3rd)
// | Col 0 | Col 1 | Col 3 | Col 4 | Col 5 | Col 6 |
// | 1st | 2nd | 4th | 5th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(2));
// remove column now at index 3 (5th)
// | Col 0 | Col 1 | Col 3 | Col 5 | Col 6 |
// | 1st | 2nd | 4th | 6th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
// remove column now at index 3 (6th)
// | Col 0 | Col 1 | Col 3 | Col 6 |
// | 1st | 2nd | 4th | 7th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
// remove column now at index 3 (7th)
// | Col 0 | Col 1 | Col 3 |
// | 1st | 2nd | 4th |
StatsTable.removeColumn(StatsTable.getColumnModel().getColumn(3));
No for loop needed?
-
October 20th, 2017, 07:06 PM
#22
Re: jtable column blues
What I want is
// | Col 0 | Col 2 | Col 3 |
// | 1st | 3rd | 4th |
and this :
// | Col 0 | Col 6 |
// | 1st | 7th |
I have problems removing the last column or first column
The following code removes everything but Col 0(in ref to eg 1.)
Code:
public void Remove( int col_index){
TableColumn tcol = StatsTable.getColumnModel().getColumn(col_index);
StatsTable.removeColumn(tcol);
for(int i=2;i<=StatsTable.getColumnCount();++i)
{Remove(4);}
Remove(1);
In ref to ex 2 the folllowing code gives
Code:
Remove(6);
Remove(5);
Remove(4);
Remove(2);
Remove(1);
Gives me col 3 and I want col 2
[/code]
Funny thing it works fine in one part of the program but not another.In the other the headers disappear .
Last edited by Azoth; November 3rd, 2017 at 07:30 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|