jtree

Disabling 3-Click Edit of a JTree node but keeping keyoard keys to edit for saving the old name of the node prior to edit

≡放荡痞女 提交于 2019-12-24 03:01:05
问题 I want to be able to edit the nodename with F2 and ENTER keys only, not with mouse. I added these 2 lines and they are working: jTree1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "startEditing"); jTree1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "startEditing"); But how do I disable editing from mouse? Are there any methods like: jTree1.setToggleClickCount(2); The reason I want to do this is that I want to keep the old name of the node, so I'll create a

JTree convertValueToText return is truncated when with changed

穿精又带淫゛_ 提交于 2019-12-24 02:59:10
问题 I have a custom JTree implementation that implemts convertValueToText . This implementation depends on some global state. If the returned string is longer (actually I think wider as in pixels triggers it) than a previously returned string, the text will be truncated and padded with "...". This is true when the redrawing is caused by (de)selecting the element or a repaint on the tree. Is it valid to implement convertValueToText in such a way? (I recognize that the tree display will not

Is it proper to update a tree node using `nodeChanged`

…衆ロ難τιáo~ 提交于 2019-12-24 02:22:08
问题 I have a JTree and a JTextField . When I select a node on the tree, the text field will display the value of the node. I can then edit the text and save it to change the selected node's value. I use the DefaultTreeModel 's nodeChanged method to update the tree. Is this a proper way to tell the tree model to update its node? To me it looks ugly because I'm explicitly accessing the tree's model and telling it that something has happened. Here's some code import java.awt.BorderLayout; import

highlight the treeNode in the Jtree using the treeNode itself

六月ゝ 毕业季﹏ 提交于 2019-12-23 20:24:16
问题 I have a JTree ( myTree ) and in another class, I have a DefaultMutableTreeNode which was taken from myTree . In a certain function, I want the JTree to highlight the node. I tried: myTree.setSelectionPath(new TreePath(treeNode)); but visually nothing is happening. any ideas? UPDATE: I have also another JTable which is rendered based on the selected treeNode in myTree . The table is updating correctly . It's just the myTree which refused to update visually. 回答1: You need to use the actual

JTree nodes won't get visually selected

馋奶兔 提交于 2019-12-23 19:24:21
问题 Somehow I am not able to enable a "select highlight" for my JTree nodes. I am working with a custom cell renderer in my project (which most likely causes this problem). This is the full renderer class code: protected class ProfessionTreeCellRenderer extends DefaultTreeCellRenderer { private final JLabel label; public ProfessionTreeCellRenderer() { label = new JLabel(); setBackgroundSelectionColor(Color.BLUE); setOpaque(true); } @Override public Component getTreeCellRendererComponent(JTree

Netbeans GUI Builder: how to edit generated code

给你一囗甜甜゛ 提交于 2019-12-23 05:29:09
问题 Im using Netbeans GUI Builder and I am adding a JTree to my form, as it does Netbeans is generating all the code for the JTree. What i want to know is, is there a way in Netbeans to add code to the generated code... like in the source view in the Generated Code section it creates jTree = new javax.swing.JTree(); i want to add populateJTree.addNodes(null, folder) so it looks like jTree = new javax.swing.JTree(populateJTree.addNodes(null, folder)); Is there a way of doing this 回答1: i sorted it,

JTree dynamically updating with arraylist changes

人盡茶涼 提交于 2019-12-23 03:12:47
问题 I looked for answer but wasn't able find anything to solve this. I have two array lists containing Strings that're changing dynamically after user click, and now creating JTree that will show elements from one list depends on some type in another list. I have a problem because I always add and delete something in my list and need JTree to show that changes. It will add all elements from List correctly till I expand, after that it's impossible to update content of JTree, at least for me. If I

Sharing children among parents in a JTree

白昼怎懂夜的黑 提交于 2019-12-22 09:40:11
问题 I have a custom DefaultMutableTreeNode class that is designed to support robust connections between many types of data attributes (for me those attributes could be strings, user-defined tags, or timestamps). As I aggregate data, I'd like to give the user a live preview of the stored data we've seen so far. For efficiency reasons, I'd like to only keep one copy of a particular attribute, that may have many connections to other attributes. Example: The user-defined tag "LOL" occurs at five

java swing: add custom graphical button to JTree item

橙三吉。 提交于 2019-12-22 08:12:44
问题 i would like to add an additional button with a small icon to the right of an item in a JTree. can this be done? if so, how? thanks! 回答1: You will need to CustomCellRenderer which implement TreeCellRenderer, and attach it to JTree. In your CustomCellRenderer you can put button and icon. JTree tree = new JTree(rootVector); TreeCellRenderer renderer = new CustomCellRenderer(); tree.setCellRenderer(renderer); Check this example: (referenced above code from here) http://www.java2s.com/Code/Java

Java: Recursive Search of TreeModel via it's UserObject field?

此生再无相见时 提交于 2019-12-22 08:03:59
问题 I have a Jtree using DefaultTreeModel, each individual node contains a UserObject containing various string fields. I would like to find and select a node by doing a recursive traversal until it finds the DefaultMutableTreeNode with UserObject matching one of it's fields and programmatically select that node. Are there any examples involving searching via DefaultMutableTreeNode's UserObject fields? 回答1: DefaultMutableTreeNode has depthFirstEnumeration() and breadthFirstEnumeration(). Call the