• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

JTable -Cut Copy Paste

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic