• Post Reply Bookmark Topic Watch Topic
  • New Topic

Select highlighted jTable Columns and add to another jtable  RSS feed

 
Dominic Abrams
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to copy the highlighted selected columns from a single table and add it to another Jtable? The way I'm trying to do this is to have the add and remove buttons left of the second table to add the selected columns from the above table and remove button to remove those columns I initially added. I'm new and currently learning how to use JavaSwing, but I'm unsure how I would implement this.




Screen-Shot-2016-03-13-at-3.56.02-AM.png
[Thumbnail for Screen-Shot-2016-03-13-at-3.56.02-AM.png]
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dominic, welcome to the Ranch!

Looks like you're off to a good start, at least you have a reference to both models. From there I would just translate your requirements into method calls: you want to add a column to one model, so you'd call its addColumn() method. Presumably you want to copy that column's data from one model to the other? Then just go down the column in the "from" model and get the cell data out using getValueAt(), and put it into the "to" model using setValueAt(). Remove a column from a model? There should be a method for that too. But you have code which is using addRow(); your requirements don't mention adding rows so that's probably not the right thing to do.

Just one other suggestion: Don't let the code for moving a column between two models get mixed up with other code. You said you wanted buttons to do that, but that doesn't mean that the data-moving code has to be mixed in with the button-responding code. Write a method to do the data-moving part, then call that method from your action listener.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again
I can never remember anything about tables, but there is a section in the Java™ Tutorials about them.
I am moving this discussion to our GUIs forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!