Cut paste Menu Commands

M

Matt S

I have searched through various places but can't seem to find a
solution to what should be a simple problem.

I am trying to implement cut / paste / select all commands in a JMenu.
(JDK 1.5)

I have a JFrame with JInternal Frames.

When I try to work out which text component has the focus I get null as
the JMenu now has the focus.

i.e

((JTextComponent)scrollableDesktop.getSelectedFrame().getFocusOwner()).cut();

always throws null pointer exception.

This means I don't know which component to copy cut from or paste to.
There must be a solution to this isn't there?
 
M

Matt S

this did the trick

KeyboardFocusManager focusManager =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
focusManager.addPropertyChangeListener(
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (("focusOwner".equals(prop)) &&
(e.getNewValue() != null) &&
((e.getNewValue()) instanceof JTextComponent))
{
last = (JTextComponent)e.getNewValue();
}
}
}
);

store the last JTextComponent that had the focus!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top