• Post Reply Bookmark Topic Watch Topic
  • New Topic

copy selected data from JTable's cell to clipboard  RSS feed

 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a jtable that I would like to copy from a cell that I select to clipboard. How could I do these. Do you know some example?
Many thanks and sorry for my english!
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable supports copying selected cells to the clipboard out of the box. Try it for yourself - select something and press Ctrl-C. I believe that JTable uses the toString method on objects provided by its table model to obtain the text to put into clipboard (so with the standard objects like strings and numbers you don't need anything to do). Columns are separated by tabs and each row goes on separate line, obviously.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:JTable supports copying selected cells to the clipboard out of the box.


That's true -- and when I tried it on a JTable displayed from some of my code I found that Ctrl-C resulted in a whole row being selected. That's because row selection is the default for JTable. It's possible to configure a JTable so that individual cells are selected, but I didn't try doing that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!