jtree

Change the icon of Jtree Root Node

戏子无情 提交于 2019-12-12 04:44:18
问题 Below is the code i have created a Jtree with root Node "Data Generation.. rootNode = new DefaultMutableTreeNode("Data Generation"); treeModel =new DefaultTreeModel(rootNode); tree = new JTree(treeModel); tree.setEditable(true); I have changed the icon images for the leaf node childNode=new DefaultMutableTreeNode(existingtagnames.get(len).toString()); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); ImageIcon imageIcon = new ImageIcon(Generate_Explorer

Java: DefaultMutableTreeNode Event When Renamed

十年热恋 提交于 2019-12-12 01:48:30
问题 I created a class that extends DefaultMutableTreeNode. It has a variable, "resource" of the type Resource so that it can be linked to an object without that object affecting its name. The Resource class has a variable, "name" that I would like to be changed when its corresponding DefaultMutableTreeNode is renamed, but I can't find any such events. 回答1: In DefaultTreeCellEditor there is this method: http://docs.oracle.com/javase/7/docs/api/javax/swing/tree/DefaultTreeCellEditor.html

Highlighting specific nodes in a jtree depending on data stored in the node

大兔子大兔子 提交于 2019-12-11 20:33:16
问题 I have an application that displays a jTree. Each node in the tree has a boolean field called flagged which indicates whether it requires attention or not from the user. If the field is true , then I would like it to be highlighted in red, otherwise no highlighting. What is a good way to accomplish this? Should I extend DefaultTreeCellRenderer ? Implement my own custom TreeCellRenderer ? Some other method? 回答1: Since the custom rendering you want to do is pretty basic, I would just extend

How to not collapse the node in JTree after the node is edited

╄→尐↘猪︶ㄣ 提交于 2019-12-11 16:46:38
问题 I want to know how to implement this feature: I have editable JTree where I can edit name of the nodes. If I have some node which is branch node (it has some leaf nodes in it) and this branch node is expanded while editing, after editing, this node will be collapsed. I want to leave that branch node open if it is open and collapsed if it is collapsed, after editing is done. I tried to look at TreeWillExpandListener but it seems it does not solve my problem because I need to recognize if

Java Issue with Tree Selection

坚强是说给别人听的谎言 提交于 2019-12-11 15:49:30
问题 In my program, I have 2 JTrees and there is a common treeselection listener for both. The problem happens when I select a node in the first tree and then immediately select a node in the second tree.Now if I were to go back and select the same node in the first tree that was initially selected, nothing happens. How do I solve this? Is there a way to unselect a node at the end of a valueChanged event handler? After Editing: Now if I only do if ( tree == tree1 ){ if(!tree2.isSelectionEmpty()){

case insensitive for jTree

时光总嘲笑我的痴心妄想 提交于 2019-12-11 15:14:43
问题 I am kinda new in java because I mainly study autoIt language. I am trying to learn JTree and Action Listener . I have this code(actually came from internet: sorry I forgot the link.) which have a jTree sample and filtering for the search functionality. I tweaked a bit of the code so that I can understand it on my own. The code works perfectly fine. Tho, when I search, I need to input the exact word to be able to see the result. How can I make the search words case-insensitive(or I don't know

Change The icon of a certain Node in JTree?

一曲冷凌霜 提交于 2019-12-11 13:52:52
问题 I have a JTree and nodes of it are driven from DefaultMutableTreeNode. Each node can be verify or not.At first the icon of all nodes are the same but, I am going to change the ICON of the verified nodes when I select them and press the verify button. I want to have the ability to click and write on each node so I can not use JLabel to show icons . I made the following code but it returns NULLException. class CustomIconRenderer extends DefaultTreeCellRenderer { ImageIcon defaultIcon; ImageIcon

How to create a JTree with JCheckbox to Show Systems All drives and its Folders/Files

ε祈祈猫儿з 提交于 2019-12-11 12:47:22
问题 I am beginner in java. I am creating a file chooser that can select multiple drives, folders or files at a time for worm scanning purpose. I have written the code to work fine for a single drive (e.g. c:\ or e:\ etc). I am trying to create a tree for all drives in system. Please tell me how to accomplish this. Code import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; import java.io.File; import java.util.Collections; import java.util.Vector; public class FileTreeDemo {

Assign unique ID to a DefaultMutableTreeNode in a JTree?

岁酱吖の 提交于 2019-12-11 11:57:30
问题 I have a Jtree that I can add new Nodes to. I need to assign a unique ID to each new node. I was thinking of extending the DefaultMutableTreeNode Class but I guess it didn't work or I did it wrong. So, how can I do this. An example would be nice. Thanks. 回答1: My impression is that DefaultMutableTreeNode works "best" without extending it, but wrapping your own user-defined object. And that could have an ID. Nevertheless your way should work too, when creating a nodes children with your own

JTree Editor not setting variables

不打扰是莪最后的温柔 提交于 2019-12-11 10:14:12
问题 I am trying to use a Renderer in a JTree for a Swing application I am developing, the custom renderer is used only when the tree is a leaf object and is composed of a flow layout. An empty label with an image, a JComboBox and finally a label that contains a String. Initially the Renderer is passed a string value via the getTreeCellRendererComponent() method in HazardRenderer.java it is then set using the setText() method in HazardComboBox.java the editor then takes the selected renderer