jtree

swing - Triggering Tree Cell Edit Event

狂风中的少年 提交于 2020-01-02 04:28:27
问题 I have a JTree with editable nodes. How can I programmatically trigger the tree cell edit event, i.e. bring up the node-renaming textbox in place of a highlighted node, as if the user manually highlighted it and pressed F2? Basically I want to add a "Rename" menu item or toolbar button, to clue users in on that particular function of the tree, and I want it to function identically to an F2 keypress when the user highlights a node. 回答1: 1) some node is selected (by Mouse / KeyBoard event) and

How to edit a JTree node with a single-click

邮差的信 提交于 2019-12-30 11:14:04
问题 I have a JTree , and would like for its getTreeCellEditorComponent() method to be invoked when I single click on a node. According to the documentation for the DefaultTreeCellEditor class (which I extended), "Editing is started on a triple mouse click, or after a click, pause, click and a delay of 1200 miliseconds." Is there some way to override this behavior, so that a single-click could start the editing process? 回答1: The JTree API recommends a MouseListener , but a key binding is also

How to programmatically fire a MouseEvent to a MouseListener with Java?

孤街醉人 提交于 2019-12-30 08:53:09
问题 I have a JTree with a custom associated MouseListener (for showing popup etc.). I need to fire a MouseEvent that will be caught by the MouseListener . How should I do that programmatically? 回答1: You could create your own MouseEvent and loop through all the listeners and make the call. For example: MouseEvent me = new MouseEvent(tree, 0, 0, 0, 100, 100, 1, false); for(MouseListener ml: tree.getMouseListeners()){ ml.mousePressed(me); } 回答2: The Robot class might be what you're looking for. This

How to programmatically fire a MouseEvent to a MouseListener with Java?

僤鯓⒐⒋嵵緔 提交于 2019-12-30 08:52:19
问题 I have a JTree with a custom associated MouseListener (for showing popup etc.). I need to fire a MouseEvent that will be caught by the MouseListener . How should I do that programmatically? 回答1: You could create your own MouseEvent and loop through all the listeners and make the call. For example: MouseEvent me = new MouseEvent(tree, 0, 0, 0, 100, 100, 1, false); for(MouseListener ml: tree.getMouseListeners()){ ml.mousePressed(me); } 回答2: The Robot class might be what you're looking for. This

Java: How to programmatically select and expand multiple nodes in a JTree?

穿精又带淫゛_ 提交于 2019-12-30 06:05:51
问题 I have a JTree and an awt.Canvas . When i select multiple objects from within the Canvas into the objList , I want all the selected items to be shown inside the JTree as selected. That means for example if I have 2 objects selected, both their paths to root should be expanded, and also each selected object should have its corresponding TreeNode selected. My JTree has TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION . Here is a sample of the expand funcion i use : public void selectTreeNodes()

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

久未见 提交于 2019-12-29 09:21:07
问题 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;

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

和自甴很熟 提交于 2019-12-29 09:21:07
问题 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;

Double-click a JTree node and get its name

淺唱寂寞╮ 提交于 2019-12-29 01:37:29
问题 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. 回答1: 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

Java Swing: Need a good quality developed JTree with checkboxes

大憨熊 提交于 2019-12-28 03:04:44
问题 I was looking for a a JTree implementation, that contains checkboxes and which: When you select one node, all its successors in the tree are automatically selected When you unselect one node, all its successors in the tree are automatically unselected When a parent node is already selected, and the selection was removed from one of its successors, the node color will be changed, to make it intuitive that although this parent node is selected, not all of its successors are selected (Like when

How to add checkbox to JTree node to manage multiselection?

泪湿孤枕 提交于 2019-12-28 02:59:07
问题 I want to build JTree which has nodes that contain check box + icon + data and tree selection algorithm. 回答1: This is full example that demonstrate how to add checkbox to Jtree node. I used JTree with nodes based on File system content. I usesd also AddCheckBoxToTree.CheckTreeManager class to manage selection or semi selection options. Use public AddCheckBoxToTree.CheckTreeManager getCheckTreeManager() { return checkTreeManager; } method to play with selection tree path. for example: // clear