jtree

FileTreeModel Multiple Roots

依然范特西╮ 提交于 2021-02-07 08:57:20
问题 I use this code here to create a file tree model. I want it to browse files. How can I add multiple roots? E.g. list C:/, D:/, E:/. 回答1: A TreeModel can only have one root node, but you can use JTree.setRootVisible() to hide the root node when displaying the tree. Modify your model to have a virtual root node that contains each filesystem root (C:\, D:\, E:\, etc.), and call JTree.setRootVisible(false) on your JTree. 来源: https://stackoverflow.com/questions/10501410/filetreemodel-multiple

Change the color of one or more nodes in Jtree dynamically

大憨熊 提交于 2021-01-28 14:12:38
问题 I have created Jtree with Root node and 4Subnodes. My problem is like this: I need to change the foreground and background color of a particular node dynamically. How can i do it? Help me with some piece of code. Thank you all in advance... 回答1: How can i do it? I'm sure that JTree tutorial contains valuable info about DefaultTreeCellRenderer, Help me with some piece of code. tons of examples here or here or here 回答2: One easy way I found was to include HTML markup in the node text. The

How do i change color of Jtree based on my dynamic changing Jtree for java desktop application

醉酒当歌 提交于 2020-07-31 05:50:17
问题 Everyone, I'm making desk app with JPanel and JFrame . Here is my tree structure: Default tree @Root |-L1B (node-1) |-L2A (node-2) |-L1A (node-3) After this i'm reading a file (let's suppose two values: value1 and value2 ) and add leaf data. So, I'de like to change the color like this: @Root |**-L1B** (node-1)(with green color) | value1(with green color) | value2(with green color) |-L2A (node-2) |-L1A (node-3) value1 value might be 60s, meaning that for 60s it will in be green and then become

overriding JTree double-click to prevent node expansion?

时光毁灭记忆、已成空白 提交于 2020-05-12 11:32:28
问题 It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself. Is there a way to stop this 2nd mechanism? I would like to override the double-click on a node so it does something (updates another display to show statistics on the node being double-clicked), and would like it to not expand/collapse the tree node. (just to be clear: I don't want to prevent the

overriding JTree double-click to prevent node expansion?

痴心易碎 提交于 2020-05-12 11:31:06
问题 It looks like there are 2 default mechanisms to expand a folder node in a JTree. One is to click on the expanded/collapsed icon next to a node. The other way is to double-click on the node itself. Is there a way to stop this 2nd mechanism? I would like to override the double-click on a node so it does something (updates another display to show statistics on the node being double-clicked), and would like it to not expand/collapse the tree node. (just to be clear: I don't want to prevent the

JTree with form builder

泪湿孤枕 提交于 2020-05-09 05:20:29
问题 I created a form with default NetBeans edito and put a jTree on it. It somehow then creates bunch of elements such as "colors", "sports", "food" in there. But it is not in the creation code. Where is it coming from and how can I edit it... Even if I do jTree1.removeAll(); everything is still there... and non of my code for adding new items to the jTree working. private void test(java.awt.event.MouseEvent evt) { //trying to remove all, but it does not remove anything jTree1.removeAll(); //it

JTree: how to check if current node is a file

老子叫甜甜 提交于 2020-02-05 02:35:05
问题 I am using the following code to populate a JTree which is working perfectly File [] children = new File(directory).listFiles(); // list all the files in the directory for (int i = 0; i < children.length; i++) { // loop through each DefaultMutableTreeNode node = new DefaultMutableTreeNode(children[i].getName()); // only display the node if it isn't a folder, and if this is a recursive call if (children[i].isDirectory() && recursive) { parent.add(node); // add as a child node listAllFiles

How do I customize a JComboBox so that the pop-up is a JTree (instead of a list)?

为君一笑 提交于 2020-01-24 05:28:06
问题 I am trying to create a combo box so that I can put whatever control I prefer within the pop-up, in my specific case a JTree. Having a look at how the JComboBox is implement, the pop-up is really created by the UI delegate. The problem in changing that is that it would need to be re-implemented for each look and feel, which is something I do not want to do... I basically want a component that it has the look and feel of a JComboBox (in the current look and feel) and the popup is a JTree (in

TreeCellEditor: must select cell to edit even if ShouldSelectCell return false

穿精又带淫゛_ 提交于 2020-01-21 05:52:06
问题 I need to use custom cell renderer for my JTree to add some JLabel on each cell. And then allow the user to click on these label without needing to select the cell first. So, i've created a Renderer which return a JPanel that contains a DefaultTreeCellRenderer and 2 JLabel. public class TreeNodeRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer { private JPanel panel1 = new JPanel(); private JLabel delete = new JLabel(""); private JLabel upload = new JLabel(""); public

How to search a particular node in jtree and make that node expanded.?

泪湿孤枕 提交于 2020-01-18 04:44:29
问题 I am having a jtree with 100 nodes. now i want to search particular node from that tree and make that node expanded..? How can i solve this problem.? 回答1: Expanding on @mKorbel's answer and as discussed in How to Use Trees, you can search your TreeModel recursively and obtain a TreePath to the resulting node. Once you have the desired path , it's easy to reveal it in the tree. tree.setSelectionPath(path); tree.scrollPathToVisible(path); Addendum: Here's one way to "obtain a TreePath ."