jtree

Color row in JTree

拥有回忆 提交于 2019-11-27 07:54:49
问题 I'd like to color elements in a JTree. However, simply adding a background color only to the label looks kind of strange. Particularly if more than one node is selected, the resulting shape looks ragged and distracting. Is there a way to make the background extend the whole width of the tree element, so that the whole row gets colored? Either starting at the left border or starting at the beginning of the label, but definitely extending till the right border of the component? Here is a small

Jtable as a Jtree Node

孤街浪徒 提交于 2019-11-27 06:48:48
问题 I know you can create a table and add a JTree as a column. But what I want to do is the complete opposite. Check the image and tell me if this is possible. Thanks! UPDATE: By using MKorbel's code and by randomizing the number of columns with the following code: @Override public int getColumnCount() { int i = (int) (Math.random( )* 10.0); if (i%2 ==0) return 2; else return 3; } I was able to get the following image: 回答1: 1) I didn't solve isLeaf() in Renderer and Editor somehow 2) if I put

Java detect CTRL+X key combination on a jtree

主宰稳场 提交于 2019-11-27 06:37:33
问题 I need an example how to add a keyboard handler that detect when Ctrl + C , Ctrl + X , Ctrl + C pressed on a JTree . I were do this before with menu shortcut keys but with no success. 回答1: You can add KeyListeners to any component (f) f.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if ((e.getKeyCode() == KeyEvent.VK_C) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { System.out.println("woot!"); } }

Customizing Tree.collapsedIcon for a single JTree

空扰寡人 提交于 2019-11-27 05:37:32
I know that you can change the Tree.collapsedIcon for a all JTrees in an application using Swing using the UImanager . For example: UIManager.put("Tree.collapsedIcon",closedcabinet); I would like the flexibility of changing the Tree.collapsedIcon for individual JTrees in the same application with the end result being that the Tree.collpasedIcon could appear differently for different trees in the same application. I know how to customize individual icons using a custom renderer. For example, I use setIcon to set the icon of a leaf, SetOpenIcon to set the icon for a node that has children when

Change JTree node icons according to the depth level

…衆ロ難τιáo~ 提交于 2019-11-27 05:18:46
I'm looking for changing the different icons of my JTree (Swing) The java documentation explains how to change icons if a node is a leaf or not, but that's really not what I'm searching. For me it doesn't matter if a node is a leaf or, I just want to change the icons if the node is in the first/2nd/3rd depth level of the three. As an alternative to a custom TreeCellRenderer , you can replace the UI defaults for collapsedIcon and expandedIcon : Icon expanded = new TreeIcon(true, Color.red); Icon collapsed = new TreeIcon(false, Color.blue); UIManager.put("Tree.collapsedIcon", collapsed);

Where are these error and warning icons as a java resource?

点点圈 提交于 2019-11-27 04:33:22
问题 I've got a custom tree cell renderer that I'm using to render custom icons a JTree, and I really like the warning icon and the error icon that JOptionPane displays for both warning messages and error messages respectively. Obviously I can use the following code to get the icons for my own use, but this is way heavy handed and requires me to instantiate dialogs that I'm never going to use: public class ValidationCellRenderer extends DefaultTreeCellRenderer { private Icon warnIcon; private Icon

How can I refresh a JTree after adding some nodes to the underlying model?

有些话、适合烂在心里 提交于 2019-11-27 01:51:46
问题 First of all, let me say that I dont use the DefaultTreeModel. I implement my own TreeModel, so i cant use the DefaultXXX stuff. The problem is this: Through some addStuff() methods which my model defines I add nodes to the underlying data structure. I then notify listeners by calling treeNodesChanged() inside the addStuff() function (I Know there are treeNodesInserted methods but it is the same thing. It just notifies listeners with a different method). Now, one of the listeners is a static

JTree, Optimization algorithm, Java

╄→尐↘猪︶ㄣ 提交于 2019-11-26 22:10:24
问题 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

Put JTable in the JTree

霸气de小男生 提交于 2019-11-26 20:58:05
in connection with thread Jtable as a Jtree Node I put JTable to JTree, but JTree View isn't rendered correctly on start_up, how can I setPreferredSize for JTable , because PreferredScrollableViewportSize shrinked JTable with rendering TableHeader + one Row , one Row remain hidden, but after expanding Node(s) TreeRenderer change and repaint the setPreferredSize to the expected Dimension import java.awt.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import javax.swing.tree.*; public class TreeWithTableRenderer extends JFrame { private static final long serialVersionUID =

Java: How to display an XML file in a JTree

佐手、 提交于 2019-11-26 20:46:43
问题 I would like to have a way to display the contents of an XML file in a JTree . I have already accomplished this using DOM, by implementing a custom TreeModel (and TreeCellRenderer ). However it is very clunky (much workaround-ery and hackery) and rather rough around the edges. Is anyone aware of a way to get a JTree to display the contents of an XML file, parsed with SAX? Thanks! 回答1: Here's the code that I use. It is based on the API of Dom4J, but you can easily convert it to the APIs of