Hello,
In my program I'm using JTree and I'm having problem with adding JScrollPane. Can somebody please help me?
mainTab = new JTabbedPane(JTabbedPane.TOP); mainTab.setBackground(Color.LIGHT_GRAY); frame.getContentPane().add(mainTab, BorderLayout.CENTER); JPanel panel = new JPanel(); mainTab.addTab("New tab", null, panel, null); mainTab.setBackgroundAt(0, Color.WHITE); JScrollPane scrollPane = new JScrollPane(mainTab); frame.getContentPane().add(scrollPane); Container cp = new Container(); panel.add(cp); Schools = new DefaultMutableTreeNode("Schools",true); model = new DefaultTreeModel(Schools); //model.addTreeModelListener(new MyTreeModelListener()); EuropeanSchoolLuxembourg = new DefaultMutableTreeNode("School Name",true); Schools.add(EuropeanSchoolLuxembourg); treeNode2 = new DefaultMutableTreeNode("Building A"); EuropeanSchoolLuxembourg.add(treeNode2); treeNode3 =new DefaultMutableTreeNode("Room A1"); treeNode2.add(treeNode3); treeNode4 = new DefaultMutableTreeNode("Room A2"); treeNode2.add(treeNode4); /*DefaultMutableTreeNode for Uni */ Uni = new DefaultMutableTreeNode("Uni",true); treeNode2 = new DefaultMutableTreeNode("Building A"); Uni.add(treeNode2); treeNode3 =new DefaultMutableTreeNode("Room A1"); treeNode2.add(treeNode3); treeNode4 = new DefaultMutableTreeNode("Room A2"); treeNode2.add(treeNode4); Schools.add(Uni); /* JTree */ final JTree tree = new JTree(model); tree.setAutoscrolls(true); tree.setEditable(true); tree.setFont(new Font("Segoe UI Semibold", Font.PLAIN, 11)); tree.setBorder(UIManager.getBorder("Tree.editorBorder")); /*JScrollPane*/ JScrollPane treePane = new JScrollPane(); treePane.setBounds(271, 11, 19, 154); treePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); treePane.setViewportView(tree); cp.add(treePane, BorderLayout.CENTER);
I think that Im not adding the JScrollPane correctly, can somebody help me? Thank you very much for your Help