jtree

Difficulties understanding the renderers mechanism of swing's JTable and JTree

北战南征 提交于 2019-11-26 17:52:06
问题 Often, when using JTable or JTree user writes and assign it is own specific cell renderer. It is very common to inherit user's component from DefaultTableCellRenderer , and implements the renderer method getTableCellRendererComponent . It turns out that DefaultTableCellRenderer in fact inherits from JLabel, thus returns himself (this) when called to super (at the render method) and thus user's renderer can similarly returns himself (this) as well. And it all works well. My question is how can

Filtering on a JTree [closed]

隐身守侯 提交于 2019-11-26 17:46:44
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 12 months ago . Problem Applying filtering on a JTree to avoid certain nodes/leaves to show up in the rendered version of the JTree . Ideally I am looking for a solution which allows to have a dynamic filter, but I would already be glad if I can get a static filter to work. To make it a

easy and fast JTree Cell Editor

浪尽此生 提交于 2019-11-26 17:18:53
问题 I have a JTree with a custom TreeModel and a custom TreeRenderer. The Tree Model contains a bunch of objects of different types. One of these types is displayed differently than the others: The displayed text is a concatenation of two fields of the object. When i edit the cell, I want to update one of these fields with the edited text. So far i got it working pretty well. My Problem: It is confusing when the text, which is displayed while editing, is the complete concatenated value of 2

Java JTree directory structure from file paths

与世无争的帅哥 提交于 2019-11-26 16:44:14
I've been trying to get my head around this so maybe some of you can help me. I have a list of files with their full paths (these are just strings the files are on another machine), e.g: C:\a\b\c\file1.txt C:\a\b\c\file2.txt C:\a\d\file3.txt C:\e\file4.txt I want to create a Jtree to show the directory structure like this: C: a b c file1.txt file2.txt d file3.tct e file4.txt I've been spliting the string on the seperator so I end up with a list of arrays like: "C:","a","b","c","file1.txt" "C:","a","b","c","file2.txt" "C:","a","d","file3.txt" "C:","e","file4.txt" Now I want to add them an index

Updating ImageIcon in JTree without repainting the Tree?

↘锁芯ラ 提交于 2019-11-26 14:55:05
问题 Basically I edit an attribute private string status="OK" in the UserObject() of a DefaultTreeNode() . I have a CustomRenderer which implements DefaultCellRenderer , which sets the Icon by rendering the "OK" attribute of UserObject of a TreeNode . Originally, when I select a node, the icon changes. I am using Tree.revalidate() & Tree.repaint() , and the change is being reflected. However, I am not sure if this very efficient. What would be the proper way of doing this? I tried doing TreeModel

JTree add nodes on startup of application

蓝咒 提交于 2019-11-26 14:55:04
问题 I want to make text editor with file browser so when I start my application I want to my program add nodes on JTree so it shows me all files and folders for example in My Documents folder, and to give me ability to access to those files and folders (especially to folders). I tried to figure out how Andrew Thompson did that from this example but I failed. I managed to create nodes for all files and folders from My Documents using this example . But thats all, I can't figure out how to generate

JTree: Set custom open/closed icons for individual groups

梦想的初衷 提交于 2019-11-26 14:39:49
问题 I know how to set custom leaf icons in JTree I know how to set custom closed/open icons for all group nodes But I can not set custom open/closed icons based on the group node names, for example of node could be called Emails (so it is nice to have an envelop icon) or one group may be called tasks and so on. I tried to do this by overriding the getTreeCellRendererComponent method of class DefaultTreeCellRenderer But changing the icon for the current node will affect for the next node only! How

Change JTree node icons according to the depth level

妖精的绣舞 提交于 2019-11-26 11:33:34
问题 I\'m looking for changing the different icons of my JTree (Swing) The java documentation explains how to change icons if a node is a leaf or not, but that\'s really not what I\'m searching. For me it doesn\'t matter if a node is a leaf or, I just want to change the icons if the node is in the first/2nd/3rd depth level of the three. 回答1: As an alternative to a custom TreeCellRenderer , you can replace the UI defaults for collapsedIcon and expandedIcon : Icon expanded = new TreeIcon(true, Color

How does JTree display file name?

懵懂的女人 提交于 2019-11-26 09:04:41
问题 In my project, I am trying to add a file explorer so the user can select files from a given directory. I want to limit this view to the project\'s root folder (which is determined by the user). This is very much like Eclipses Package Explorer, as the \"workspace\" is determined by the user. Currently files do not display the full path (from C:) which is what I want, but all of the folders display the full path (Which I do not want, i just want the folder name). So how does JTree display these

Java JTree directory structure from file paths

江枫思渺然 提交于 2019-11-26 04:56:01
问题 I\'ve been trying to get my head around this so maybe some of you can help me. I have a list of files with their full paths (these are just strings the files are on another machine), e.g: C:\\a\\b\\c\\file1.txt C:\\a\\b\\c\\file2.txt C:\\a\\d\\file3.txt C:\\e\\file4.txt I want to create a Jtree to show the directory structure like this: C: a b c file1.txt file2.txt d file3.tct e file4.txt I\'ve been spliting the string on the seperator so I end up with a list of arrays like: \"C:\",\"a\",\"b\