Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • 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){
Always the selected cell is taken as 1.
Any ideas!!!
[ 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.

    Bookmark Topic Watch Topic
  • New Topic