• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help With JTabbed Pane

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I have a JTabbedPane with 5 JPanels added to it. Each JPanel has its own components like text field, TextArea , JTable etc....

I am trying to implement Cut, Copy, Paste functionality for all these Jpanels. Ctrl+x, Ctrl+v, ctrl+c works fine as it is inbuilt with windows but when i try to implement with event hadler i am facing the problem.

i6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent h)
{
JScrollPane scrollPane = (JScrollPane)p1.getSelectedComponent();
JTextPane textPane = (JTextPane)scrollPane.getViewport().getView();
textPane.copy();
}
});

would work fine provided JScrollPane is the only component in th my JPanel but that is not the case how do i find out what is the component he is copying from(may be TextArea, JTable, etc)..

Otherway i tried is using getText() method that is there in textArea but again the same proble comes that is textArea is not the only component in my JPanel.

In short i would like to copy everything that is selected by the mouse irespective of the component.

Please help me.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For an easy way see the menu code and discussion for the DragPictureDemo2 example in the How to Use Drag and Drop and Data Transfertutorial: last section Adding Cut/Copy/Paste Support.
If you decide to do it on your own you might consider the TextAction class. It has a handy getFocusedComponent method that returns the focused JTextComponent.
 
reply
    Bookmark Topic Watch Topic
  • New Topic