jtree

get nested List of CustomObject from JTree, including leaf

寵の児 提交于 2019-12-13 17:24:02
问题 Get List<List<CustomObject>> from JTree I was populating the JTree according to this question... Recursively populate JTree, using list of list using the Answer https://stackoverflow.com/a/56090968/7339033 List<List<Pair>> listOfListPair = new ArrayList<>(); listOfListPair.add((List<Pair>) Arrays.asList( new Pair[]{new Pair(1, 1), new Pair(3, 1), new Pair(1, 2)})); listOfListPair.add((List<Pair>) Arrays.asList( new Pair[]{new Pair(1, 1), new Pair(3, 1), new Pair(3, 1)})); listOfListPair.add(

How to replace a JTree component in Java Swing?

谁都会走 提交于 2019-12-13 05:24:18
问题 I am wondering how to make the following code in replacing the JTree component working. Currently I am getting a java.lang.NullPointerException at RandomJTree$1.keyPressed(RandomJTree.java:64) at java.awt.Component.processKeyEvent(Component.java:6221) at javax.swing.JComponent.processKeyEvent(JComponent.java:2801) at java.awt.Component.processEvent(Component.java:6040) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java

Swing JTree how custom Render get value from custom Editor?

对着背影说爱祢 提交于 2019-12-13 05:09:03
问题 I try to make JTree with custom TreeRenderer public class TextCellRender implements TreeCellRenderer { JPanel panel; JTextArea text; JLabel label; LayoutManager Layout; public TextCellRender() { text = new JTextArea(); text.setWrapStyleWord(true); text.setLineWrap(true); text.setSize(360, text.getPreferredSize().height); label = new JLabel(); panel = new JPanel(); panel.add(label); panel.add(text); } @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean

Easiest way to clone a whole JTree/TreeModel?

纵饮孤独 提交于 2019-12-13 04:16:20
问题 Do i really have to implement the deep-clone myself or are there any library methods to get a deep clone of an JTree or it's TreeModel? 回答1: As said by @SteveKuo, why do you need to clone a TreeModel ? TreeModel can be shared amongst different instances of JTree . Here is a sample demo of two JTree's sharing the same model. Alternatively, you could create twice the same TreeModel : import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import

How to resize horizontal jtree java swing by mouse when application is running?

人走茶凉 提交于 2019-12-13 04:05:48
问题 I'm a new Java Swing programer, I've got java basic. I want to create a form include jtree, jtree can be resized horizontal by mouse when application is running. How can I do that? Thanks for your help! 来源: https://stackoverflow.com/questions/19854885/how-to-resize-horizontal-jtree-java-swing-by-mouse-when-application-is-running

how does a JTree respond to a changed DefaultMutableTreeNode?

南楼画角 提交于 2019-12-13 00:19:30
问题 Just trying to work out what happens, in terms of threads, if you change the user object of a DefaultMutableTreeNode in a non-EDT thread? I'm not talking about the DefaultTreeModel events, namely insertNodeInto and removeNodeFromParent, which I'm pretty clear should always be run in the EDT... I think... In the case of changes to nodes' user objects, it appears that JTree.TreeModelHandler is the thing which is "listening" for such events... but is there reason to expect that the listener will

jtree programmatic multi selection

隐身守侯 提交于 2019-12-12 11:33:55
问题 Is there an ability to select multiple tree nodes in JTree programmatically? I've set multiselection mode by tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); And all I need - make my application be able to select some nodes programmatically. But I've didn't found the way how to do that. Could anybody give advice how to solve this? Thanks 回答1: import java.awt.Dimension; import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*;

Change JTree row height resizing behavior when rendering

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:50:59
问题 I want to use a custom TreeCellRenderer containing three text fields only when a node is SELECTED, while use the default renderer when the node is NOT SELECTED. The problem is that although I've set an appropriate preferred and minimum size for the panel, JTree does not update the edited row height. On the contrary when I use the same panel as an editor, it is rendered correctly. Can someone explain why this is happening? Is there a recommended way to achieve a rendering resizing behavior

JTree model.nodechanged(Node) loses data

元气小坏坏 提交于 2019-12-12 05:38:54
问题 I am testing some code with JTree , and I noticed that model.reload() gives different output than model.nodeChanged(currentNode) . The correct output is obtained from model.reload() . Here are my two outputs for the same code: My code is as follows: public class test { private JFrame frame; JTree tree; DefaultMutableTreeNode root; DefaultTreeModel model; private Map<String, DefaultMutableTreeNode> treeMap; public static void main(String[] args) { test t = new test(); try { Thread.sleep(1000 *

DefaultTreeCellRenderer() execute periodically

一世执手 提交于 2019-12-12 04:54:06
问题 I write some program for monitoring processes on unix server. The main part of my code is looking like this: Class FeedMonitor { //............. private volatile boolean monitor = true; private volatile String feedShRez; private volatile DefaultMutableTreeNode envNode; //............. public void prepareGUI() { //.............. // SwingWorker worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { sh = new Shell(env); System.out.println("Swing