treecellrenderer

JTree nodes won't get visually selected

馋奶兔 提交于 2019-12-23 19:24:21
问题 Somehow I am not able to enable a "select highlight" for my JTree nodes. I am working with a custom cell renderer in my project (which most likely causes this problem). This is the full renderer class code: protected class ProfessionTreeCellRenderer extends DefaultTreeCellRenderer { private final JLabel label; public ProfessionTreeCellRenderer() { label = new JLabel(); setBackgroundSelectionColor(Color.BLUE); setOpaque(true); } @Override public Component getTreeCellRendererComponent(JTree

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

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

Highlighting specific nodes in a jtree depending on data stored in the node

大兔子大兔子 提交于 2019-12-11 20:33:16
问题 I have an application that displays a jTree. Each node in the tree has a boolean field called flagged which indicates whether it requires attention or not from the user. If the field is true , then I would like it to be highlighted in red, otherwise no highlighting. What is a good way to accomplish this? Should I extend DefaultTreeCellRenderer ? Implement my own custom TreeCellRenderer ? Some other method? 回答1: Since the custom rendering you want to do is pretty basic, I would just extend

Change The icon of a certain Node in JTree?

一曲冷凌霜 提交于 2019-12-11 13:52:52
问题 I have a JTree and nodes of it are driven from DefaultMutableTreeNode. Each node can be verify or not.At first the icon of all nodes are the same but, I am going to change the ICON of the verified nodes when I select them and press the verify button. I want to have the ability to click and write on each node so I can not use JLabel to show icons . I made the following code but it returns NULLException. class CustomIconRenderer extends DefaultTreeCellRenderer { ImageIcon defaultIcon; ImageIcon

Changing text style of DefaultMutableTreeNode

十年热恋 提交于 2019-12-07 16:44:25
问题 I have created a custom JTree. That tree could be filtered to show only those nodes that contains given criteria (string). Now, is there any way to bold only that part of DefaulMutableTreeNode that contains searched string? If a tree node has label = "StackOverflow" and user is searching for nodes that contains "Stack", "StackOverflow" node would be rendered with "Stack" part bolded. How to achieve that? 回答1: You need to set your own TreeCellRenderer. Example: The code below produces this

TreeItem selection width in a TreeView

你说的曾经没有我的故事 提交于 2019-12-06 07:42:19
问题 I'm using JavaFX 8 and I'm currently doing some GUI developments. I have a little problem with my TreeView and I need your help. Do you know if it is possible, in a TreeView, to select just the label and not the whole width of the TreeCell ? I mean (Netbeans example) : Instead of : Thank you in advance. 回答1: Please try adding a Label inside TreeCell. for example: private static class YourItemCell extends TreeCell<YourItem> { Label label; public YourItemCell() { label = new Label(); }

Change JTree row height resizing behavior when rendering

拜拜、爱过 提交于 2019-12-04 06:55:13
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 similar to that of editing? Is there a method provided by JTree to set it directly or is it necessary to

How do you make components of JPanel as a node in JTree usable?

旧时模样 提交于 2019-11-29 15:59:08
When I click on the JButton nothing happens. This applies even for a JScrollPane that I put in (it shows, but will not scroll). Why is the JPanel not at the front? I get the sense that something has to be overridden. Should it be the expansion of the part that is not the arrow? If so, how is that done? import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.tree.*; public class test { public test() { JTree tree = createTree(); tree.setToggleClickCount(0); tree.setRowHeight(50); tree.setCellRenderer(new PanelRenderer()

Set icon to each node in Jtree

与世无争的帅哥 提交于 2019-11-29 06:41:58
I want to set for each node in my JTree a different icon, actually I'm loading each node from a data base, with a "while", I set each icon like a root, leaf or parent. Like this: All my declarations are global: private ResultSet myResultSet; protected DefaultTreeModel treeModel; private DefaultMutableTreeNode rootNode,childNode,parent1,parent2; And this is the code where I set my nodes: myResultSet=rtnNodes(); /*Method that returns a RS with my nodes*/ while(myResultSet.next()){ switch(myResultSet.getInt(1)){ /*The first column is the type of node: root, parent, leaf...*/ case 0: treeModel =