jtree

JTree set background of node to non-opaque

守給你的承諾、 提交于 2019-12-22 04:39:15
问题 Please have a look at the SSCCE. How can I make the non-selected tree nodes' background transparent. At the moment the background of non-selected nodes is white. My cell renderer, however, should paint it non-opaque if it is not selected (and green when selected...what it does). In the end I want non-selected nodes to be just text without background, since the area which is red in the SSCCE has a gradient fill in my application. import java.awt.BorderLayout; import java.awt.Color; import java

Java JTree expand only level one nodes

﹥>﹥吖頭↗ 提交于 2019-12-22 03:19:29
问题 With a JTree, assuming the root node is level 0 and there may be up to 5 levels below the root, how can I easily expand all the level 1 nodes so that all level 1 & 2 branches and leafs are visible but levels 3 and below aren't? 回答1: Thanks for the quick response guys. However I have now found the simple solution I was looking for. For some reason I just couldn't see DefaultMutableTreeNode.getLevel() in the JavaDocs! FYI what I'm doing now is: DefaultMutableTreeNode currentNode = treeTop

Java: JTree with plus/minus icons for expansion and collapse?

試著忘記壹切 提交于 2019-12-22 00:19:04
问题 How do I make my Jtree look like something below, with plus and minus icons that allows expansion and collapse? Currently, the default JTree only expands and collapses when you double click. I want to override this double click for another functionality and let the user expand/collapse the tree by only clicking on the minus and plus icons such as below. 回答1: with plus and minus icons that allows expansion and collapse? These are the default icons for the Windows LAF. Other LAF's have

How to rename a node in jtree

陌路散爱 提交于 2019-12-21 23:24:04
问题 I create a Jtree that all of its nodes have User object, I fill user object by ItemInfo class, now my problem is with renaming a node. I can edit my node but since I try to find my UserObject I saw when I press F2 and rename my node, new name place in my UserObject! So now I want to know I should touch where to replace new name of my node with previous name manually? I guess I need to write my own DefaultTreeCellRenderer class, please advice me... (if yes any example for my reference) public

changing how Nimbus LaF handles JTree node highlighting

蓝咒 提交于 2019-12-21 09:39:09
问题 I have been working to transition a Java application from WindowsLookAndFeel to Nimbus, largely successfully, despite Nimbus foibles. My users overall like the Nimbus LaF but didn't like some details, some of which I changed by consulting previous questions on this site. Example: I copied the LeafIcon, ClosedIcon and OpenIcon from Windows LaF (which they liked) and use them in the Nimbus version, for a nice combination of LaFs. Stuck on one last (?) problem. I have a JTree with a subclassed

How to use JTree to display files from a directory in JPanel?

≯℡__Kan透↙ 提交于 2019-12-20 07:37:54
问题 I am working on developing a GUI using Swing. The GUI is implemented in such a way that the when the user wants to load a set of text files, then the filechooser dialog should open and the user selects the directory in which all the files are present. Now, I want to list all the files in the selected directory into a JScrollPane using JTree. I am using this example to implement JTree in my code: http://www.java2s.com/Code/Java/File-Input-Output/FileTreeDemo.htm However, the JTree is not

Proper manner create Class, JTree, DefaultTreeCellRenderer using JTextPane

青春壹個敷衍的年華 提交于 2019-12-20 07:27:07
问题 I have this class in order to show multiple colors in a leaf using JTree... The class is TextPaneDefaultTreeCellRenderer import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.tree.*; public class TextPaneDefaultTreeCellRenderer extends DefaultTreeCellRenderer { TextPaneTreeCellRenderer textPaneScrollPane = new TextPaneTreeCellRenderer(); public TextPaneDefaultTreeCellRenderer() { initialize(); } private void initialize() {

JTree avoid collapse after reload

孤者浪人 提交于 2019-12-20 06:39:42
问题 I'm trying to find a solution the problem of collapse in JTree after reload it. The situation: JTree [-] Office A |---[-] Office A.1 | |---[-] Office A.1.1 | |---[-] Office A.1.2 [-] Office B |---[-] Office B.1 | |---[-] Office B.1.1 | | |---[-] Office B.1.1.1 Now I have to add the Office A.1.3 . To do this I get the Office A.1 and with the method add(DefaultMutableTreeNode aNode) I add Office A.1.3 . OfficeA1.add(OfficeA13); After this I call the reload method on the DefaultTreeModel of the

JTree - how to add nodes with a For-Loop?

老子叫甜甜 提交于 2019-12-20 06:30:10
问题 I have a simple JTree , that systematically adds nodes from relevant vars: public void init() { final String section1 = "JAVA"; final String section1_content1 = "Tutorial1"; final String section1_content2 = "Tutorial2"; final String section1_content3 = "Tutorial3"; final String section1_content4 = "Tutorial4"; final String section1_content5 = "Tutorial5"; final String section1_content6 = "Tutorial6"; final String content1a = "Introduction"; final String content1b = "Hello World!"; // Create

I would like to put the information to add in jpanel jscrollpane when you click each tree node

杀马特。学长 韩版系。学妹 提交于 2019-12-20 05:46:24
问题 I would like to put the information to add in jpanel jscrollpane when you click each tree node... Please...!!! 1.I want to control that state selected tree node at Tree.java where Frame.java Tree.java package pms; import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class Tree extends JTree { private JTree tree; public static int