CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    54

    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.

  2. #17
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: jtable column blues

    Quote Originally Posted by Azoth View Post
    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?

  3. #18
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    54

    Re: jtable column blues

    Quote Originally Posted by jcaccia View Post
    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

  4. #19
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    54

    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

  5. #20
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: jtable column blues

    Quote Originally Posted by Azoth View Post
    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
    Quote Originally Posted by Azoth View Post
    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));

  6. #21
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    54

    Re: jtable column blues

    Quote Originally Posted by jcaccia View Post
    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?

  7. #22
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    54

    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.

Page 2 of 2 FirstFirst 12

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
  •  





Click Here to Expand Forum to Full Width

Featured