Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help With JTabbed Pane

 
Abdul Hameed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic