java - How to invoke JTable action from outside JButton? -
i have jtable
transferhandler
allows copy-cut-paste actions via hotkeys or dnd. have 3 jbuttons
(copy-cut-paste) outside of jtable
, should invoke similar actions on jtable's transferhandler
(such canimport()
etc).
how can that?
basically similar approach in recent question/answer: find table's copy action in actionmap, wrap custom action delegates original , use custom action in button:
table.setdragenabled(true); final action copy = table.getactionmap().get("copy"); action copywithbutton = new abstractaction("copy") { @override public void actionperformed(actionevent e) { copy.actionperformed( new actionevent(table, e.getid(), e.getactioncommand())); } }; frame.add(new jscrollpane(table)); frame.add(new jbutton(copywithbutton), borderlayout.north); frame.add(new jscrollpane(new jtextarea(5, 20)), borderlayout.south);
Comments
Post a Comment