Java Get jTree Node Text

How To Get Selected Node Text From JTree Using Java NetBeans

jtree selected node text



In this Java Tutorial we will see How To Get The Selected JTree Node Text Using DefaultMutableTreeNode And Display The Value Into A JTextFields On JTree Mouse Clicked Event In Java NetBeans .




Project Source Code:


private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {                                    
        
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        jTextField1.setText(selectedNode.getUserObject().toString());
        
    }


OutPut:

java get jtree selected node index




Share this

Related Posts

Previous
Next Post »