我正在创建自定义弹出菜单,仅使用扩展JComponent
作为菜单项并扩展JWindow
以保存它们。我的问题是 - 如何在单击(必须)执行剪切/复制/粘贴操作JComponent
时从实例发送信号?MouseListener
JTextField
编辑:
我将尝试更准确地解释。
JTextField 类(简化):
public class TextInputField extends JTextField implements FocusListener {
private MenuPopupWindow popUp;
public TextInputField() {
popUp = new MenuPopupWindow();//MenuPopupWindow class extends JWindow
MenuItem paste = new MenuItem("Paste",
new ImageIcon(getClass().getResource("/images/paste_icon.png")),
"Ctrl+V");//MenuItem class extends JComponent, has implemented MouseListener - and when mouseClicked(MouseEvent e) occurs, somehow action signal have to be sent to this class
MenuItem copy = ....
MenuItem cut = ....
Action pasteAction = getActionMap().get(DefaultEditorKit.pasteAction);
paste.setAction(pasteAction);//How to make it to work?
popUp.addMenuItem(paste);
popUp.addMenuItem(cut);
popUp.addMenuItem(copy);
}
}
怎么做才对?