jtree

DefaultTreeModel and Wicket Tree: setAsksAllowsChildren doesn't work

偶尔善良 提交于 2019-12-02 14:32:48
问题 I'm using Wicket's Tree component in a web app. But empty folders are shown in a file-way. Just like this: Bellow is where I use the DefaultTreeModel and Tree: PDMinterface pdmI = new PDMinterface(); DefaultMutabletreeNode rootTreeNode = pdmI.getDocTree(); //文档树根结点,由PDM接口提供 DefaultTreeModel treeModel = new DefaultTreeModel(rootTreeNode); treeModel.setAsksAllowsChildren(true); and I'm sure that folder5 is set to allow children: public DefaultMutableTreeNode getDocTree(){ DefaultMutableTreeNode

TreePath to java.io.File

非 Y 不嫁゛ 提交于 2019-12-02 11:32:42
问题 Is there any easy way of getting a File (or java.nio.file.Path , for that matter) from a TreePath ? For example, you have a JTree like this: Green |---Blue |---Red |---Yellow |---Purple.jpg |---Brown.jpg |---Black.jpg If you have a TreePath going to Black.jpg , is there a way to get a File (or Path ) with path Green\Yellow\Black.jpg ? I can do it the long way, by taking parents/children one by one and constructing the path bit by bit, but I was hoping there might be a more elegant way... 回答1:

Creating a JTree out of an XML document using DOM parser

左心房为你撑大大i 提交于 2019-12-02 09:06:26
问题 package xml; import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import java.io.*; public class ThirdParser extends JFrame{ DocumentBuilderFactory factory; DocumentBuilder builder; File f; Document d; JTree tree; JScrollPane scroll; //------------------------------------------------------------------------------ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ @Override

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

倾然丶 夕夏残阳落幕 提交于 2019-12-02 09:02:16
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 displayed in the JPanel after I select the directory. I have placed the JTree code in the actionPerformed()

JTree selection issue

☆樱花仙子☆ 提交于 2019-12-02 07:40:20
问题 I've got a JTree with nodes made up of a JLabel and a JComboBox. What I want is that when clicked on, the selected JComboBox will expand, but it seems like the first click is being consumed by the JTree itself (?), so I have to click it twice. Here is the code I have: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.plaf.ColorUIResource; import javax.swing.tree.*; public class JComboBoxJTree

How to set transparent background for JTree cell?

元气小坏坏 提交于 2019-12-02 06:39:12
问题 Folks, I am trying to create a gradient JTree control. The following code mostly works except that the background for the tree cell is not transparent. I would appreciate it if someone call tell me what is it that I am not doing right. Thank you in advance for your help. Regards, Peter package TestPackage; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.*; public class Test { public Test() { JFrame frame =

TreePath to java.io.File

这一生的挚爱 提交于 2019-12-02 05:20:16
Is there any easy way of getting a File (or java.nio.file.Path , for that matter) from a TreePath ? For example, you have a JTree like this: Green |---Blue |---Red |---Yellow |---Purple.jpg |---Brown.jpg |---Black.jpg If you have a TreePath going to Black.jpg , is there a way to get a File (or Path ) with path Green\Yellow\Black.jpg ? I can do it the long way, by taking parents/children one by one and constructing the path bit by bit, but I was hoping there might be a more elegant way... You can do this pretty simply with a short regex and the toString method, heres a quick example: TreePath

Swing JTree with Checkbox and JFileChooser

好久不见. 提交于 2019-12-02 03:33:17
问题 By using JFileChooser I am able to select file and folders getting JList with File Objects and I am showing it with checkbox. Now my requirement is like I want to show the selected file and folder in tree structure with checkbox and the checkbox should be only for root elements not for all child elements. Example : For Example, I selected folders ABC and PQR which containt sub folders and few files now on UI It should be display Checkbox1 ABC-- --SubFolders . --SubFolder . --Files --Files

How to set transparent background for JTree cell?

自作多情 提交于 2019-12-02 03:16:39
Folks, I am trying to create a gradient JTree control. The following code mostly works except that the background for the tree cell is not transparent. I would appreciate it if someone call tell me what is it that I am not doing right. Thank you in advance for your help. Regards, Peter package TestPackage; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.*; public class Test { public Test() { JFrame frame = new JFrame(); JPanel framePanel = new JPanel(); framePanel.setLayout(new BorderLayout()); frame

How can I add checkbox in tree table

一笑奈何 提交于 2019-12-02 03:13:42
I want to created a Tree with multi-columns. I found this tutorial here (German) and this answer (English). I want to add checkboxes in one column, but I have no idea how to do it. When I return a checkbox to JTreeTable , something show in execute is checkbox detail not checkbox object. How can I get something like this , pictured below? trashgod As shown in Taking the New Swing Tree Table for a Spin , cited here , your implementation of RowModel must return the correct type from getColumnClass() and the correct value from getValueFor() . Values of type Boolean.class will be rendered with a