jtree

Swing: how can I ignore deselection events?

久未见 提交于 2019-12-25 04:39:07
问题 My custom component is composed of three JTree s inside a JPanel . Only one JTree should be selected at a time, so I've added a TreeSelectionListener to each of them that calls clearSelection() on the previously selected JTree . (See here for more details). That works fine, but I need to prevent the TreeSelectionListener s to trigger when a JTree is deselected . A simple way to distinguish a selection event from a deselection one would be more than enough. Thanks in advance! 回答1: Just get the

Putting properties file into a JTree rather than just displaying it

血红的双手。 提交于 2019-12-25 02:32:56
问题 This is my current code - it just displays the key pair values from my GitCommands.properties file and displays it in my GetAllProperties.java file - is it possible to sort it so it goes in to a JTree rather than just displaying it in a list type format? import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Enumeration; import java.util.Properties; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class

Showing a JTable in a JTree behaves differently with different look and feels

泪湿孤枕 提交于 2019-12-25 01:08:29
问题 I have a JTree where some of the data to be shown should be shown in a JTable. So to do this, I created a renderer class (extending DefaultTreeCellRenderder) to change the rendered component returned depending on what the object value contains when initially passed into the renderer. If it is a table to be shown, it is contained within a JScrollPane (as the below code shows). This works (in that the JScrollPane containing the JTable is shown in its entirety) with the Cross Platform Look and

Binding HashMap<String, String> to MutableTreeNode

谁说我不能喝 提交于 2019-12-24 13:16:19
问题 I need to bind a Hashmap to a MutableTreeNode so that I can display that in a JTree . I have the following code: static Map<String, String> form = new LinkedHashMap<String,String>(); I guess this is how I need to implement MutableTreeNode . I just don't know how to procees now to get the Key's of "form" to show up in the MutableTreeNode . public class MyNode implements MutableTreeNode { @Override public Enumeration children() { // TODO Auto-generated method stub return null; } @Override

jtree make user see updates via “blinking” (rapid change of color)

给你一囗甜甜゛ 提交于 2019-12-24 09:57:49
问题 I have a JTree presenting information (via DefaultMutableTreeModel). This information is either from user actions or from asynchronous messages over the network. My question is, is it possible to make the text of a tree node to start "blinking" (I guess this is a rapid change of color) so that the user is alerted that something new has beed added? If yes how? Thanks! 回答1: There are 2 parts of the problem. Detecting recently changed nodes. You can add TreeModelListener to your model and get

How to ensure that text is rendered to fit in tree?

北战南征 提交于 2019-12-24 09:39:12
问题 JTree does not seem to automatically resize its nodes to accommodate fonts of size 20+ . I've tried calling revalidate() , but that doesn't seem to help. The text in the nodes appears "squished" vertically so that the top and bottom of letters are clipped. How can I use large fonts and ensure that they are displayed properly with a JTree ? 回答1: Some LAFs (e.g. WindowsLookAndFeel) set a fixed rowHeight which is rather arbitrary (like 16px ). Be sure either to force the tree to dynamically

Desktop view in JTree - Swing - Windows Only

六月ゝ 毕业季﹏ 提交于 2019-12-24 04:25:16
问题 I would like to get a desktop view in JTree , something like this: I have a sample code which shows only the c:\ , since I am new to Java, finding difficulties to achieve it. Here is my code so far: public class FileTreeDemo { public static void main(String[] args) { File root; if (args.length > 0) { root = new File(args[0]); } else { root = new File(System.getProperty("user.home")); } System.out.println(root); FileTreeModel model = new FileTreeModel(root); JTree tree = new JTree(); tree

Increase size of Text in Jtree

喜你入骨 提交于 2019-12-24 04:13:05
问题 I'm trying to increase the size of the text of nodes in my Jtree. Is there any way to do this with/without altering other swing components? Thanks! 回答1: Use JTree.setFont. For example: final Font currentFont = tree.getFont(); final Font bigFont = new Font(currentFont.getName(), currentFont.getStyle(), currentFont.getSize() + 10); tree.setFont(bigFont); 来源: https://stackoverflow.com/questions/8120213/increase-size-of-text-in-jtree

Restricting the addition of nodes of a JTree except for the 1st level child

青春壹個敷衍的年華 提交于 2019-12-24 03:25:31
问题 I have been trying a lot of approaches on how to limit my code on adding nodes only to the 1st level. This means that the user can only add nodes to the 1st level children of a JTree. Adding a node in my program can be done in 2 ways 1. Add node button 2. Select > Right click > Add node (In here, I wanted to disable this behavior if it a non 1st level child is selected. It's a long shot though ) I need a validation that permits the addition of nodes in other levels. Thanks! Here is the

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:59
问题 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