jtree

Display file(s) name and select it under the folder in JTree

谁说我不能喝 提交于 2019-11-29 17:20:51
I managed to come this far using stackoverflow examples, JTree displays all the system drives and folders, wanted to display all the corresponding files from the folder as well, got all the file names in a loop need to add them, that's where I got stuck! Please give me direction to add the files under the folder, Thanks! CODE: public class viewGui extends JFrame { private FileSystemView fileSystemView; private Desktop desktop; private static final long serialVersionUID = 1083130296343096642L; public static JTree tree; private DefaultTreeModel treeModel; private JTable table; private

How do you make components of JPanel as a node in JTree usable?

旧时模样 提交于 2019-11-29 15:59:08
When I click on the JButton nothing happens. This applies even for a JScrollPane that I put in (it shows, but will not scroll). Why is the JPanel not at the front? I get the sense that something has to be overridden. Should it be the expansion of the part that is not the arrow? If so, how is that done? import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.tree.*; public class test { public test() { JTree tree = createTree(); tree.setToggleClickCount(0); tree.setRowHeight(50); tree.setCellRenderer(new PanelRenderer()

How to change style (color, font) of a single JTree node

独自空忆成欢 提交于 2019-11-29 14:16:17
I have two JTree in two panels in a JFrame . I want to change the style(color and font) of nodes on drag and drop from one tree to the other.Please provide me a way to change the color of a JTree node permanently. To start, you will need to have a data object that can handle style and color. You could subclass DefaultMutableTreeNode and add these data items with getts and setters Then you'd need to create a custom TreeCellRenderer. I recommend extending DefaultTreeCellRenderer, and in the overridden handler, checking for your custom class, and modifying the JLabel output to use the Font and

How do I auto-expand a JTree when setting a new TreeModel?

大城市里の小女人 提交于 2019-11-29 09:13:31
I have a custom JTree and a custom JModel ; I would for the JTree to "auto-expand" when I give it a new model. At the moment, it simply collapse all the nodes to the root. Here is an example: private class CustomTree extends JTree { @Override public boolean isExpanded(TreePath path) { return ((Person) path.getLastPathComponent).hasChildren(); } private class CustomTreeModel extends TreeModel { // ... omitting various implementation details @Override public boolean isLeaf(Object object) { return !((Person) object).hasChildren(); } } Model model = new Model(); Person bob = new Person(); Person

Set icon to each node in Jtree

与世无争的帅哥 提交于 2019-11-29 06:41:58
I want to set for each node in my JTree a different icon, actually I'm loading each node from a data base, with a "while", I set each icon like a root, leaf or parent. Like this: All my declarations are global: private ResultSet myResultSet; protected DefaultTreeModel treeModel; private DefaultMutableTreeNode rootNode,childNode,parent1,parent2; And this is the code where I set my nodes: myResultSet=rtnNodes(); /*Method that returns a RS with my nodes*/ while(myResultSet.next()){ switch(myResultSet.getInt(1)){ /*The first column is the type of node: root, parent, leaf...*/ case 0: treeModel =

JTree with checkboxes

▼魔方 西西 提交于 2019-11-28 23:30:09
I need to add checkboxes to a JTree. A custom TreeCellRenderer/TreeCellEditor seems like the right approach. So far I used the CheckBoxNodeRenderer approach in this webpage . It works OK except for two things: there's additional whitespace above + below the checkbox; I'd like to keep it the same as a regular JTree. I would like to distinguish between clicking on the checkbox itself (which should attempt to toggle the checkbox) and clicking on the text associated with the checkbox (which should allow an event listener to interpret this as clicking on the corresponding tree node and take

How to refresh XML in Jtree

删除回忆录丶 提交于 2019-11-28 14:05:33
I read here , but if the xml file changes the jtree does not reload /refreshes how to create a function for refresh / reload Jtree I try to write code : refreshAction = new AbstractAction("Refresh", IconFactory.getIcon("delete", IconFactory.IconSize.SIZE_16X16)) { public void actionPerformed(ActionEvent e) { XMLTree xmlClass = null; ((DefaultTreeModel) xmlClass.getModel()).reload(); System.out.println("Refresh"); }}; but i got the error : java.lang.NullPointerException I added a new Action to popup in getJPopupForExplorerTree() . You'll probably want to re-factor xmlFile out of the XMLTree

How to remove folder symbol which comes in front of each node from JTree in java

ぐ巨炮叔叔 提交于 2019-11-28 13:52:14
I am trying to remove the folder symbol from node of JTree which comes by default. How can I accomplish this? Just for reference, here's a complete example: import java.awt.Component; import java.awt.EventQueue; import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.UIManager; /** @see http://stackoverflow.com/questions/5260223 */ public class JTreeLite { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { //@Override public void run() { createGUI(); } }); } private static void createGUI() { final

Double-click a JTree node and get its name

自作多情 提交于 2019-11-28 13:33:42
How do I double-click a JTree node and get its name? If I call evt.getSource() it seems that the object returned is a JTree. I can't cast it to a DefaultMutableTreeNode. From the Java Docs If you are interested in detecting either double-click events or when a user clicks on a node, regardless of whether or not it was selected, we recommend you do the following: final JTree tree = ...; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if(selRow

DefaultMutableTreeNode-Text is too long?

依然范特西╮ 提交于 2019-11-28 12:50:38
问题 I have some DefaultMutableTreeNode's. While the programm's running, I can change the text and revalidate it. But if the text is too long, so for example the text "tested", the text will be displayed as "te...". How do I change this ? Thanks 回答1: you have to read tutorial about JTree, and examples how to use TreeCellRenderer if you'll real question then please update your question and add there the code in SSCCE form 回答2: the underlying reason is that the layout of the tree nodes is cached and