jtree

Multiple ITEM_STATE_CHANGED events from jcheckbox in jtree

核能气质少年 提交于 2019-12-20 04:28:19
问题 Somebody, explain me, please, how it works. Here is the code: package checkboxtree; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.util.EventObject; import java.util.Vector; import javax.swing.AbstractCellEditor; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTree;

find next occurence of tree node in java swing

你。 提交于 2019-12-20 04:20:41
问题 I have a jtree. i have written the code to search a given node in the tree when search button clicked is worked and now i have to search the next occurence if exist with another click on that button? can you help? code for search button is m_searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = searchNode(m_searchText.getText()); if (node != null) { TreeNode[] nodes = m_model.getPathToRoot(node); TreePath path = new

How can I add checkbox in tree table

随声附和 提交于 2019-12-20 03:54:09
问题 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? 回答1: 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()

JTree cell editor receives mouse clicks differently depending on OS

允我心安 提交于 2019-12-20 03:26:41
问题 I've created a tree cell renderer/editor framework that is admittedly a little bit hacky, but it works perfectly on Windows and Linux. The image below illustrates a sample setup. The goal is that if the user clicks on the image (numeral) 1 or 2, then the application responds to that click but does not select the tree row. If the user clicks on the text one or two, the application responds to that click and does select the tree row. The way I've implemented this, again, is a little hacky.

JTree avoid collapse node when update the tree

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 01:36:07
问题 I'm using a tree table object (the example taken from the sun site)..I would prevent the collapse of the tree nodes when I update the model, because it's boring to re-expand all the nodes everytime I need to update it. Can you help me? Thank you! 回答1: Without seeing the model and without knowing what exactly you mean by "update the model", just a couple of facts structure change: no way, the tree cant know if/when/which nodes are the same as before insert/remove: shouldn't touch expansion

Add 'expand' button to JTree node that has no children?

五迷三道 提交于 2019-12-20 01:13:44
问题 I'd like to add the 'expand' button to my JTree's nodes to indicate that they are expandable. The catch is that they have no children until the user clicks on them (due to processing that happens in the background). Is there any way I can set a node as a parent or having children without it actually having children? Thanks 回答1: It's possible using your own DefaultMutableTreeNode implementation overriding isLeaf(): Returns true if this node has no children. Swing Tutorial: JTree explains it

How to build a jtree dynamically

旧巷老猫 提交于 2019-12-19 11:52:44
问题 The SSCCE of the problem is as follows. I am dynamically populating JTree , but nothing is happening. import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Vector; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax

Right-click context menu for Java JTree?

≡放荡痞女 提交于 2019-12-18 10:51:17
问题 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

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

百般思念 提交于 2019-12-18 08:28:43
问题 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. 回答1: 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

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

狂风中的少年 提交于 2019-12-18 08:28:08
问题 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. 回答1: 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