Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTable copy to clipboard

Status
Not open for further replies.

themanfalconar

Technical User
Sep 13, 2003
10
0
0
EU
Hi there,

I've got a JTable from which I want to copy its entire contents to the clipboard.

When I use the mouse to select a range of cells and press CTRL+C, this works just fine.

However, I've created a button that automatically selects all cells (using the code below); when I press CTRL+C after pressing the button it does not copy to the clipboard.

Has anyone any idea how I can do this in this manner?

Cheers, Dan (code is below)
Code:
cornerButton.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent e)
       {
            int row = 0;
            int col = 0;
            boolean toggle = false;
            boolean extend = false;
            resultsTable.changeSelection(row, col, toggle, extend);

            row = rowNum; // rowNum is the number or rows
            col = colNum; // colNum is the number of cols
            toggle = false;
            extend = true;
            resultsTable.changeSelection(row, col, toggle, extend);
                
            scroll.getViewport().setViewPosition(new Point(0,0)); // scroll is the JScrollPane that the table is in
      }
}});
 
I'm willing to bet that after you click the button, the focus is still on the button. You're then copying the button object to the clipboard.

You would either need to shift the focus to the JTable - I'm not sure how - or do it in such a way that the table never loses focus in the first place. Perhaps a pop-up right-click menu on the table rows?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top