jtree

JTree and dropdown options on right clicking nodes

巧了我就是萌 提交于 2019-12-01 10:40:11
I'm trying to use the JTree and implement different drop downs for all the parent nodes and the children nodes. Here's what I've done: pmTree.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { try { if(evt.getButton() == evt.BUTTON1) { } else if (evt.getButton() == evt.BUTTON3) { TreePopup(evt); //pmTree.updateUI(); } }catch (Exception e) {} } }); and PopupCode: public void TreePopup(java.awt.event.MouseEvent evt) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) pmTree.getLastSelectedPathComponent(); popup = new

JTree and dropdown options on right clicking nodes

孤街浪徒 提交于 2019-12-01 09:07:55
问题 I'm trying to use the JTree and implement different drop downs for all the parent nodes and the children nodes. Here's what I've done: pmTree.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { try { if(evt.getButton() == evt.BUTTON1) { } else if (evt.getButton() == evt.BUTTON3) { TreePopup(evt); //pmTree.updateUI(); } }catch (Exception e) {} } }); and PopupCode: public void TreePopup(java.awt.event.MouseEvent evt) {

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

痴心易碎 提交于 2019-12-01 05:15:35
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? 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); } The Robot class might be what you're looking for. This class is used to generate native system input events for the purposes of test automation, self-running demos,

TreeCellEditor: must select cell to edit even if ShouldSelectCell return false

∥☆過路亽.° 提交于 2019-12-01 01:46:57
I need to use custom cell renderer for my JTree to add some JLabel on each cell. And then allow the user to click on these label without needing to select the cell first. So, i've created a Renderer which return a JPanel that contains a DefaultTreeCellRenderer and 2 JLabel. public class TreeNodeRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer { private JPanel panel1 = new JPanel(); private JLabel delete = new JLabel(""); private JLabel upload = new JLabel(""); public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean

Compound JTree Node allowing events to pass through to objects underneath

时光总嘲笑我的痴心妄想 提交于 2019-11-30 15:50:52
I'm trying to create a JTree in which some nodes are compound objects containing a JLabel and a JButton. The Node is representing a server and port shown by the JLabel, the JButton will use the Desktop API to open the default browser and go to the URL. I have read the following already and have followed them as closely as I can. The Node is displayed how I want it (mostly - I can deal with making it nicer later) but when I try to click on the button the JTree is responding to the events, not the button. java swing: add custom graphical button to JTree item http://www.java2s.com/Code/Java/Swing

Expand Collapse Expand Issue with JTree Lazy loading

房东的猫 提交于 2019-11-30 14:22:22
问题 I have implemented a tree using Lazy Loading. The 1st level nodes are created at the time of tree creation, where as the child nodes are created only when a user expands any particular node. The data is coming from DB, and we fire a query to the database so as to populate the child nodes. Implemented TreeExpansionListener and using overridden implementation of treeExpanded method. On expansion, I remove all child nodes for the selected node, make a DB query and add the records as child to the

Right-click context menu for Java JTree?

限于喜欢 提交于 2019-11-29 23:55:36
I'm trying to implement pop-up menus in Java JTree. I've sub-classed DefaultTreeCellRenderer (to change node appearance) and DefaultTreeCellEditor (to create Components to attach event listeners to, since apparently the Components that DefaultTreeCellRenderer.getTreeCellRendererComponent() returns can't do it?). I don't really want to "edit" the nodes, just be able to pop-up a menu when a node gets right-clicked, but this is the only way I can think of doing it right now... Below is the code that I have so far-- I'm just trying to figure out how to capture MouseEvents. It sort of works, but

Help making a JTree with a JCheckBox

元气小坏坏 提交于 2019-11-29 22:21:08
问题 I have an unusual situation where I need to have a JTree with each node containing 2 checkboxes and a label (with the ability to add a listener to tell when any of the potential checkboxes are checked). I also need the root node to have the same layout (which I'm assuming means creating a JPanel with 2 JCheckBoxes and a JLabel), with the ability to select all the checkboxes down the tree if one in the root is checked. Any guidance or examples? I've checked out previous questions on here and

DefaultMutableTreeNode-Text is too long?

喜欢而已 提交于 2019-11-29 17:31:22
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 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 the underlying reason is that the layout of the tree nodes is cached and the cache not updated properly. Might f.i. happen if the node is changed under feet of the model, uncomment the

JTree, Optimization algorithm, Java

左心房为你撑大大i 提交于 2019-11-29 17:24:35
My Partners and me, we are trying to optimize frequency process... What we want to simplify our problem as much as possible in a JTree . As you can see, each node or leaf has a numResampleOperations involved per node/leaf. L -> Increment or multiplication M -> Decrement or division How do we calculate the values? Target = Source*L/M numResampleOperations = filterSize * Source * Integer.max(L, M); We want to obtain only one value per frequency shown in the JTextField, removing not needed branch. For this example we used only 5 ordered Target frequencies (only integers value are allowed), but