trouble with createContent and JTree
Hello.
Could you please help me - I try to write my first plugin, but I don't understant how I can add some nodes into JTree.
When I use contentFactory.createContent and contentFactory.addContent() my JTree is added correctly but in a new tab of the plugin window.
If I add only the main JPanel, my JTree is added with the default values without the nodes that I have already added o_0.
Please tell me where is my mistake?
The code of my tryings is below =(:
public class Manager implements ToolWindowFactory, TreeSelectionListener { private JPanel mainPanel; private JPanel managerPanel; private JPanel ftpLayer; private JComboBox ftpConnections; private JButton doExpand; private JButton doCollapse; private JButton doClose; private JButton doRefresh; private JTree filesInConnection; private JScrollPane filesScroll; private JLabel label; @Override public void createToolWindowContent(Project project, ToolWindow toolWindow) { //make nodes - test nodes DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultMutableTreeNode lv1 = new DefaultMutableTreeNode("lv1"); DefaultMutableTreeNode lv12 = new DefaultMutableTreeNode("lv12"); DefaultMutableTreeNode lv2 = new DefaultMutableTreeNode("lv2"); root.add(lv1); lv1.add(lv12); root.add(lv2); lv2.add( new DefaultMutableTreeNode("lv21")); lv2.add( new DefaultMutableTreeNode("lv22")); lv2.add( new DefaultMutableTreeNode("lv23")); //make tree JTree filesInConnection = new JTree(root); filesInConnection.addTreeSelectionListener(this); JScrollPane filesScroll = new JScrollPane(filesInConnection); //get content factory instance ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); //create content panel Content content = contentFactory.createContent(mainPanel, "", false); Content f = contentFactory.createContent(filesInConnection, "", false);
toolWindow.getContentManager().addContent(content, 0);
toolWindow.getContentManager().addContent(f, 0); } public void valueChanged(TreeSelectionEvent arg0) { } }
Please sign in to leave a comment.
You have two different filesInConnection variables in your code: one is a field bound to a UI Designer form and another is a local variable. You're filling the wrong one with your nodes.
Thank you.
So, how can I pull and\or set data into Jtree that is bound to UI Designer?
Is it possible for me to do?
*SORRY* =)
The question is closed.
Thank you. =))))
So, if someboby is interested in this code
Use the DefaultTreeModel