jtree

Tree in scala swing

房东的猫 提交于 2019-12-05 04:34:20
I want to use a tree in my Scala swing application, but the component isn't available in the API. Does a wrapper of JTree exists ? If not, do you have any advice for making it ? Thanks Even though you can use directly the Java JTree in your scala program, as illustrated by this thread , there is a debate about including a Scala wrapper of a JTree. The following common usages are tedious, verbose, non-type safe, and/or require unsafe null usage: Creating a custom tree model, backed by your own user objects -- the Scala Swing way would be to have a standard typesafe Map behind it Events - there

JTree set background of node to non-opaque

守給你的承諾、 提交于 2019-12-05 04:08:21
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.awt.Component; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane;

Hiding/filtering nodes in a JTree?

余生颓废 提交于 2019-12-05 01:42:47
I have a data object represented in a TreeModel , and I'd like to show only part of it in my JTree --for the sake of argument, say the leaves and their parents. How can I hide/filter the unnecessary nodes? My eventual implementation: Have two TreeModel s, the underlying one and the filtered one. When a change occurs on the underlying TreeModel , rebuild the filtered TreeModel from scratch. Clone each node that should be visible, and add it to its first visible ancestor in the filtered TreeModel (or the root if none are visible). See teh codez below, if you're curious. This has the unfortunate

JTree rendering with JCheckBox nodes

旧街凉风 提交于 2019-12-05 00:50:07
I am attempting to modify the standard Swing JTree to intermingle nodes with and without checkboxes. This is an example: When I attempt to check/uncheck one of the checkboxes (the 'User 01' node in this example), the tree loses nodes: I my code is an adaptation of this example: http://forums.sun.com/thread.jspa?threadID=5321084&start=13 . Instead of embedding a JCheckBox in a DefaultMutableTreeNode like this: new DefaultMutableTreeNode(new CheckBoxNode("Accessibility", true)); I thought it made more sense to create a model node that derived from the DefaultMutableTreeNode, which I call

JTree: how to get the text of all items?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 00:11:50
问题 I want to get text of an JTree in format: root sudir1 node1 node2 subdir2 node3 node4 Is it possible? I wrote some code public static String getLastSelectedText(JTree tree) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) return null; return node.getUserObject().toString(); } But it get only selected component text. I think about expand tree and handle all nodes, but maybe it bad idea. 回答1: I think you shouldn't build the string

Java JTree expand only level one nodes

∥☆過路亽.° 提交于 2019-12-05 00:09:41
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? garyLynch 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.getNextNode(); do { if (currentNode.getLevel()==1) myTree.expandPath(new TreePath(currentNode.getPath()

Change icon of the first node of JTree

三世轮回 提交于 2019-12-04 18:57:01
问题 I want to change just the first node of a JTree icon. There is a file manager that uses JTree to show files. Here is a schematic example. How can I change the icon? Back |->Please wait(this is leaf) Folder 1 |->file1 file2 file3 Folder 2 |->file1 file2 file3 Folder 3 |->file1 file2 file3 回答1: To change the appearance of entries in a tree, use a TreeCellRenderer . E.G. /** A TreeCellRenderer for a File. */ class FileTreeCellRenderer extends DefaultTreeCellRenderer { private FileSystemView

updating JTree in java GUI

大兔子大兔子 提交于 2019-12-04 18:16:44
问题 I used a JTree in my GUI and added it to a JFrame. When I want to update it and change it's nodes in another part of my program (while program is running, as an action performed) I try to add new nodes, or remove nodes to it; But my interface doesn't change. Please suggest me a solution. regards 回答1: In addition to the insertNodeInto suggestion you can also use: DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();

Copy Paste from JTree Transferable TransferHandler

折月煮酒 提交于 2019-12-04 18:10:50
I'm exploring How to do the implementation of the Copy & Paste of JTree . Because, I want Copy from DefaultMutableTreeNode like toString() to paste in another application like Sublime Text. I was viewing the code in order to view how copy & paste is implemented and how is used drag and drop in JTree . My first thougth was, Copy and Paste between DefaultMutableTreeNode of JTree must be tested, later how paste from Clipboard to another application, but my code is not working and Don't know why is failing, and I need to solve. NOTE : Sorry my code is a bit long, because if I put only a snippet

Adding and removing nodes from a JTree

若如初见. 提交于 2019-12-04 16:45:24
问题 I have a very basic JTree . As I am on a rush, I'd prefer not to use TreeModel if it is not needed. I wrote a SSCCE to expose the problem: Sometimes I add a node. Other times I remove them. When I push Add , a node is correctly added. When I push Remove , it is supposed to remove the node, but it doesn't. Also, if I try adding more than one node, the tree stays with just the first node I added. I wrote an update method for the JTree , where I first erase all the nodes hanging from the root