Results 1 to 9 of 9
  1. #1
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default Vector/Table Deleting Row Problem.

    Hi I use Vectors with my Tables. When I Remove a row and then insert a new. It first sends empty rows equal to the number of deleted, before inserting the new one. I use code below to delete rows.

    Java Code:
    removeOrderButton.addActionListener(new ActionListener(){
                 public void actionPerformed(ActionEvent event){
                          int getRow;
                          getRow = handleAllTable.getSelectedRow();
                          handleAllModel.removeRow(getRow-1);
                         }
                });
    It´s most likley that i need to update/remove from the vector to ?

  2. #2
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Solved it, Had to create a function that removed and refreshed vector and tables. And reset an variable that hold the number of rows that were sent.

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Jeez, that sounds like you really abused a TableModel.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Why is that? Please tell me, critique makes me learn new things.

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    The DefaultTableModel does all that by itself with very little tweaking from you.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Thank you for telling me that, I now found out were the real problem is.
    I need to remove 1 from the variable that hold rowcount, when i remove a row.
    Java Code:
    countAddRows=countAddRows-1;

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ocean View Post
    Thank you for telling me that, I now found out were the real problem is.
    I need to remove 1 from the variable that hold rowcount, when i remove a row.
    Java Code:
    countAddRows=countAddRows-1;
    Why do you have to keep track of that yourself? A DefaultTableModel does all that and more.

    kind regards,

    Jos

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Amen, brother! ;)
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Mabey i have made it more difficult then it has to be. Itś like this.

    I have a combobox that i can select project to work on. Each project has 2 tables. From the first table ill send 3 column to the 3rd table and from the second table ill send 4 columns. Then i work on the data from the third table and send it to be calculated, and saved.

    I need to keep track on how many rows and so on i send. Mabey there is a better way to do it. And I will take a look at it. Remember Im just a few month old with Java. But I will start school 25 January with Java and will hopefully be as good as you guys. If thats possible.

    But it all works now. And im proud of all I have learned just by searching on the internet.

    Best Reagards / Ocean

Similar Threads

  1. Problem with vector
    By morghul in forum New To Java
    Replies: 3
    Last Post: 11-04-2009, 02:24 AM
  2. Static Vector Problem
    By calicocal in forum New To Java
    Replies: 12
    Last Post: 11-09-2008, 11:31 PM
  3. Replies: 0
    Last Post: 02-09-2008, 08:31 PM
  4. Vector problem
    By Ace_Of_John in forum New To Java
    Replies: 1
    Last Post: 01-27-2008, 08:53 PM
  5. vector problem
    By mambo_jumbo in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 10:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •