jtree

Can I use runtime parameters to fix out of bad API calls in Java?

寵の児 提交于 2020-01-13 02:41:07
问题 Not sure if this is the right spot to ask but I'm having a Java issue. I have some Java code that works in Java 6 but not in Java 7, the error is: java.lang.IllegalStateException: This function should be called while holding treeLock Using Java6 works but a few of our external users are running Java 7. I figured out the error was caused by a call to validateTree() , which works in java6 but in Java7 we need to call validate() . When I test it locally it works. Here's my problem, I started

Jtree: how to hide parts of a given defaultmutabletreenode's text?

折月煮酒 提交于 2020-01-07 05:36:06
问题 Say my JTree consists of following nodes. new DefaultMutableTreeNode("DisplayThisTextOnly {donotdisplaystringsinhere}"); how can I hide the texts between and including {} from displaying using TreeCellRenderer ? when I select this node, I want to be able to fetch the entire string again. "DisplayThisTextOnly {donotdisplaystringsinhere}" Basically my goal is to be able to fetch additional data from a given tree node without having to setObject() 回答1: Create a custom renderer and strip out the

Display remote directory/all files in Jtree

我只是一个虾纸丫 提交于 2020-01-07 02:44:30
问题 i have some problem using JSCH to retrieve files/folders and populate them in JTree. In JSCH to list files using : Vector list = channelSftp.ls(path); But i need that lists as java.io.File type. So i can get absolutePath and fileName, And i don't know how to retrieve as java.io.File type. Here is my code, and i try it work for local directory. public void renderTreeData(String directory, DefaultMutableTreeNode parent, Boolean recursive) { File [] children = new File(directory).listFiles(); //

Jtree expansion and selection problem

為{幸葍}努か 提交于 2020-01-06 08:33:33
问题 I have two JTrees instances (leftTree and rightTree). User can select some nodes from left tree and add the same to right tree. I have the below code in add button action listener to expand and select the node in rightTree after the node has been added. rightTree.updateUI(); TreePath[] paths = leftTree.getSelectionPaths(); if (null != paths && paths.length > 0) { TreePath path = paths[0]; DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); rightTree

How to serialize DefaultMutableTreeNode (Java) to JSON?

馋奶兔 提交于 2020-01-06 07:59:07
问题 How can I serialize a tree (implemented in Java using the DefaultMutableTreeNode class) to JSON (for transferring via RESTful method to an iOS client)? I tried: String jsonString = (new Gson()).toJson(topNode); // topNode is DefaultMutableTreeNode at the root It crashed with StackOverflowError . 回答1: Swing's DefaultMutableTreeNode class is a tree-like data structure which contains instances of this same type both as children and as parent . That's why Gson's default serializer ran into

Recursively populate JTree, using list of list

僤鯓⒐⒋嵵緔 提交于 2020-01-06 07:11:56
问题 this question has the reverse process in get nested List of CustomObject from JTree, including leaf I want to implement a method optimization of process, I reduced this process simple (multiplication and division) like a Tree shown. The Bottom and Bold Rectangles (the online tool don't let me change the color) represent the total multiplication between N Numerators and D Denominators of each list. Now, I was creating list of list in Java, in order to calculate the total cost of each list

how to get parent panel in java?

萝らか妹 提交于 2020-01-04 09:11:08
问题 I have created 3 panels. In the root panel I have added JTabbedPane , inside one of the tabs I have added second Panel with BorderLayout and finally in the BorderLayout.WEST the 3rd one. Inside the 3rd one I have added a JTree with PopupMenu . How can I get root panel inside actionPerformed of PopupMenu ? menuItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.println("one:"+tree.getParent().getName()); System.out.println("two:"+tree.getParent

how to get parent panel in java?

血红的双手。 提交于 2020-01-04 09:10:08
问题 I have created 3 panels. In the root panel I have added JTabbedPane , inside one of the tabs I have added second Panel with BorderLayout and finally in the BorderLayout.WEST the 3rd one. Inside the 3rd one I have added a JTree with PopupMenu . How can I get root panel inside actionPerformed of PopupMenu ? menuItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.println("one:"+tree.getParent().getName()); System.out.println("two:"+tree.getParent

Hide/change collapse [-] and expand [ ] button on JTree

别说谁变了你拦得住时间么 提交于 2020-01-04 04:01:12
问题 Is there a way to hide the collapse [-] and expand [+] button on a java file JTree ? If it's not possible, is there a way to change it to a different icon? 回答1: Yes to both: You can specify an empty Icon , as shown here. You can substitute your own implementation, as shown here. These are the relevant UIManager keys: UIManager.put("Tree.collapsedIcon", empty); UIManager.put("Tree.expandedIcon", empty); 来源: https://stackoverflow.com/questions/16953688/hide-change-collapse-and-expand-button-on

JTree with different colored tree lines?

五迷三道 提交于 2020-01-02 07:57:30
问题 is it possible to have different colored tree lines between two sibling nodes? I want to show that these two nodes are linked by having a blue line connecting them. However the entire JTree default color is grey or black angled line. Is possible to have partially different colored lines between certain nodes? 回答1: To change the colours of the lines in the tree, you will need to subclass BasicTreeUI and override at least the 4 methods: paintHorizontalLine paintHorizontalPartOfLeg