Results 1 to 2 of 2
Thread: JTree Popup
- 03-24-2009, 01:32 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
JTree Popup
This triggers a popup when I click on a Jtree
so when i select the Insert menuitem, i want to insert a new node at that position.. How can i access that node so i can create a child?
Error:
local variable node is accessed from within inner class; needs to be declared final
Thanks!Java Code:private void myPopupEvent(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); JTree tree = (JTree)evt.getSource(); TreePath path = tree.getPathForLocation(x, y); if (path == null) return; tree.setSelectionPath(path); Object obj = path.getLastPathComponent(); DefaultMutableTreeNode node = DefaultMutableTreeNode)obj; JPopupMenu popup = new JPopupMenu(); JMenuItem m1 = new JMenuItem("Insert"); m1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode check = new DefaultMutableTreeNode("test"); node.add(check); /////////// the problem is here.. how can i access the node ? } }); }
-
Similar Threads
-
Move JTree item to another JTree.
By Melki in forum AWT / SwingReplies: 8Last Post: 07-09-2009, 11:59 AM -
add PopUp menu by NetBeans
By hungleon88 in forum AWT / SwingReplies: 1Last Post: 09-12-2008, 01:05 PM -
how to create Popup Menu with Sub Menu while right-clicking the JTree Node??
By Kabiraa in forum AWT / SwingReplies: 7Last Post: 05-09-2008, 07:54 AM -
Communicating with JSP and popup
By nilz in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-20-2007, 04:29 PM -
Popup in Java
By fernando in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks