File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable -Cut Copy Paste Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable -Cut Copy Paste" Watch "JTable -Cut Copy Paste" New topic

JTable -Cut Copy Paste

Mini Pilla
Ranch Hand

Joined: Jul 15, 2001
Posts: 112
HI All,
I have Jtable,I have popup for cut,copy,paste on right click.
I ma doing that.
But my problem starts here!!!
When I copy a cell and want to paste to another cell,
how can I disable Cut and Copy because when I say

if(table.getSelectedColumnCount()==0 || table.getSelectedRowCount()==0){
Always the selected cell is taken as 1.
Any ideas!!!
[ October 28, 2002: Message edited by: Rajani Katta ]
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
A) You seem to say that once a user cuts or copies a cell, the user can't cut or copy ever again until he first pastes somewhere. Is this what you really want? Perpahs I am misunderstanding you.
B) Be careful to note the distinction between a selected cell and a cell with focus. This may cause you grief.
C) I think a cleaner way of implementing menus is to have the actions listen for the necessary events and enable/disable themselves as needed.
For example:

Then you create a MenuItem passing an instance of this action into the constructor. The menu item will take care of enabling/disabling itself whenever the action does so.
Then create the JPopupMenu with the created MenuItems. Show it when it needs to be shown. No need to recheck if the menu items should be disabled upon showing, because they do that themselves.
This approach makes the code little more modular. The definition for when each item should be enabled or not is located with the action itself. It also forces you to be explicit about what those definitions are.

I agree. Here's the link:
subject: JTable -Cut Copy Paste
It's not a secret anymore!