File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable -Cut Copy Paste

 
Mini Pilla
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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){
popcut.setEnabled(false);
popcopy.setEnabled(false);
}
Always the selected cell is taken as 1.
Any ideas!!!
Thanx
Rajani
[ October 28, 2002: Message edited by: Rajani Katta ]
 
Bill Liteplo
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic