Java Code Examples for javax.swing.JTree#convertValueToText()
The following examples show how to use
javax.swing.JTree#convertValueToText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckRenderer.java From Spark with Apache License 2.0 | 6 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, isSelected, expanded, leaf, row, hasFocus); setEnabled(tree.isEnabled()); check.setSelected(((CheckNode)value).isSelected()); label.setFont(tree.getFont()); label.setText(stringValue); label.setSelected(isSelected); label.setFocus(hasFocus); if (leaf) { Icon icon = ((CheckNode)value).getIcon(); label.setIcon(icon); } else if (expanded) { label.setIcon(UIManager.getIcon("Tree.openIcon")); } else { label.setIcon(UIManager.getIcon("Tree.closedIcon")); } return this; }
Example 2
Source File: OurTree.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * This method is called by Swing to return an object to be drawn. */ @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean isLeaf, int row, boolean isFocused) { String string = tree.convertValueToText(value, isSelected, expanded, isLeaf, row, isFocused); this.isFocused = isFocused; this.isSelected = isSelected; setText(string); setForeground(UIManager.getColor(isSelected ? "Tree.selectionForeground" : "Tree.textForeground")); preferredHeight = 0; // By default, don't override width/height if (do_isDouble(value)) { Dimension d = super.getPreferredSize(); preferredWidth = d.width + 3; preferredHeight = d.height * 2; } return this; }
Example 3
Source File: CheckBoxTreeRenderer.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, isSelected, expanded, leaf, row, hasFocus); setEnabled(tree.isEnabled()); if (value instanceof CheckNode) { CheckNode n = (CheckNode) value; check.setSelected(n.isSelected()); label.setIcon(new ImageIcon(n.getIcon())); // XXX Ask description directly } if (isSelected) { label.setForeground(LIST_FOR_COLORS.getSelectionForeground()); setOpaque(true); setBackground(LIST_FOR_COLORS.getSelectionBackground()); } else { label.setForeground(tree.getForeground()); setOpaque(false); } label.setText(stringValue); return this; }
Example 4
Source File: CheckBoxTreeCellRenderer.java From SmartIM with Apache License 2.0 | 6 votes |
/** * 返回的是一个<code>JPanel</code>对象,该对象中包含一个<code>JCheckBox</code>对象 和一个 * <code>JLabel</code>对象。并且根据每个结点是否被选中来决定<code>JCheckBox</code> 是否被选中。 */ @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); setEnabled(tree.isEnabled()); if (value instanceof CheckBoxTreeNode) { check.setSelected(((CheckBoxTreeNode)value).isSelected()); } label.setFont(tree.getFont()); label.setText(stringValue); label.setSelected(selected); label.setFocus(hasFocus); if (leaf) label.setIcon(UIManager.getIcon("Tree.leafIcon")); else if (expanded) label.setIcon(UIManager.getIcon("Tree.openIcon")); else label.setIcon(UIManager.getIcon("Tree.closedIcon")); return this; }
Example 5
Source File: CheckBoxNodeRenderer.java From jeveassets with GNU General Public License v2.0 | 5 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, false); leafRenderer.setText(stringValue); leafRenderer.setSelected(false); leafRenderer.setEnabled(tree.isEnabled()); if (selected) { leafRenderer.setForeground(selectionForeground); leafRenderer.setBackground(selectionBackground); } else { leafRenderer.setForeground(textForeground); leafRenderer.setBackground(textBackground); } Object userObject = null; if (value != null && value instanceof DefaultMutableTreeNode) { userObject = ((DefaultMutableTreeNode) value).getUserObject(); } if (value != null && value instanceof TreeList.Node) { userObject = ((TreeList.Node) value).getElement(); } if (userObject != null && userObject instanceof CheckBoxNode) { final CheckBoxNode node = (CheckBoxNode) userObject; leafRenderer.setText(node.getNodeName()); leafRenderer.setSelected(node.isSelected()); } return leafRenderer; }
Example 6
Source File: SampleTreeCellRenderer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 7
Source File: SampleTreeCellRenderer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 8
Source File: SampleTreeCellRenderer.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 9
Source File: SampleTreeCellRenderer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 10
Source File: DefaultTreeCellRenderer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 11
Source File: SampleTreeCellRenderer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 12
Source File: DefaultTreeCellRenderer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 13
Source File: DefaultTreeCellRenderer.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 14
Source File: DefaultTreeCellRenderer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 15
Source File: DefaultTreeCellRenderer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 16
Source File: SampleTreeCellRenderer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 17
Source File: DefaultTreeCellRenderer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 18
Source File: DefaultTreeCellRenderer.java From Java8CN with Apache License 2.0 | 4 votes |
/** * Configures the renderer based on the passed in components. * The value is set from messaging the tree with * <code>convertValueToText</code>, which ultimately invokes * <code>toString</code> on <code>value</code>. * The foreground color is set based on the selection and the icon * is set based on the <code>leaf</code> and <code>expanded</code> * parameters. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus); this.tree = tree; this.hasFocus = hasFocus; setText(stringValue); Color fg = null; isDropCell = false; JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground"); if (col != null) { fg = col; } else { fg = getTextSelectionColor(); } isDropCell = true; } else if (sel) { fg = getTextSelectionColor(); } else { fg = getTextNonSelectionColor(); } setForeground(fg); Icon icon = null; if (leaf) { icon = getLeafIcon(); } else if (expanded) { icon = getOpenIcon(); } else { icon = getClosedIcon(); } if (!tree.isEnabled()) { setEnabled(false); LookAndFeel laf = UIManager.getLookAndFeel(); Icon disabledIcon = laf.getDisabledIcon(tree, icon); if (disabledIcon != null) icon = disabledIcon; setDisabledIcon(icon); } else { setEnabled(true); setIcon(icon); } setComponentOrientation(tree.getComponentOrientation()); selected = sel; return this; }
Example 19
Source File: SampleTreeCellRenderer.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }
Example 20
Source File: SampleTreeCellRenderer.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * This is messaged from JTree whenever it needs to get the size * of the component or it wants to draw it. * This attempts to set the font based on value, which will be * a TreeNode. */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus); /* Set the text. */ setText(stringValue); /* Tooltips used by the tree. */ setToolTipText(stringValue); /* Set the image. */ if (expanded) { setIcon(expandedIcon); } else if (!leaf) { setIcon(collapsedIcon); } else { setIcon(null); } /* Set the color and the font based on the SampleData userObject. */ SampleData userObject = (SampleData) ((DefaultMutableTreeNode) value). getUserObject(); if (hasFocus) { setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setForeground(userObject.getColor()); } if (userObject.getFont() == null) { setFont(defaultFont); } else { setFont(userObject.getFont()); } /* Update the selected flag for the next paint. */ this.selected = selected; return this; }