Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the initialization of Netbeans JTree

Shulou Source: shulou.com Published: 2022-06-02 02:46:44 09月15日 Update

This article mainly introduces the relevant knowledge of how to realize the initialization of Netbeans JTree, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to initialize Netbeans JTree. Let's take a look.

In Netbeans JTree, the originally generated JTree is a fake tree. You can write the initialization function of JTree, and then call it after the window is initialized:

Public void treeInitialize () {DefaultMutableTreeNode root=new DefaultMutableTreeNode ("root"); try {m_DBMetaData = m_connection.getMetaData (); m_tabReset = m_DBMetaData.getTables (null, "%", "%", new String [] {"TABLES"}) While (m_tabReset.next ()) {DefaultMutableTreeNode t_newNode = new DefaultMutableTreeNode (m_tabReset.getString ("TABLE_NAME")); root.add (t_newNode);} TreeModel treeModel = new DefaultTreeModel (root); jDBTree.setModel (treeModel) } catch (SQLException e) {JOptionPane.showMessageDialog (this, "database access error"); System.exit (1);}}

This program fetches the table name from the database as the leaf node of JTree.

The response of the JTree leaf node double-click event and the acquisition of its Text:

Add MouseClicked event

Private void jDBTreeMouseClicked (java.awt.event.MouseEvent evt) {/ / TODO will add your processing code here: DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jDBTree.getLastSelectedPathComponent (); / / get the mouse click point if (selectedNode = = null) {return / / if it is not a node on the tree} if (selectedNode.isLeaf () & & evt.getClickCount () = = 2) {/ / make sure it is a leaf node and a double / / click event. ViewTable (selectedNode.toString ()); / / the parameter is the Text of the node. }} this is the end of the article on "how to initialize Netbeans JTree". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to realize the initialization of Netbeans JTree". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Node event knowledge content data database article code value function parameter masterpiece easy to operate article easy to understand more see program industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Xiaomi Huawei Shulou Technology