Package javax.swing.tree

Examples of javax.swing.tree.TreeCellRenderer


     * @return the string representation of the cell value as it will appear in the
     *   table, or null if the path is not visible.
     */
    public String getStringAt(TreePath path) {
        if (path == null) return null;
        TreeCellRenderer renderer = getDelegatingRenderer().getDelegateRenderer();
        if (renderer instanceof StringValue) {
            return ((StringValue) renderer).getString(path.getLastPathComponent());
        }
        return StringValues.TO_STRING.getString(path.getLastPathComponent());
    }
View Full Code Here


        return getTextForNodeObject(lastPathComponent);
    }

    private String getTextForNodeObject(Object lastPathComponent) {
        JTree tree = getTreeComponent();
        TreeCellRenderer renderer = (TreeCellRenderer) eventQueueRunner.invoke(tree, "getCellRenderer");
        if (renderer == null)
            return null;
        Component c = renderer.getTreeCellRendererComponent(tree, lastPathComponent, false, false, false, 0, false);
        if (c != null && c instanceof JLabel) {
            return ((JLabel) c).getText();
        }
        return lastPathComponent.toString();
    }
View Full Code Here

        return escapeSpecialCharacters(text);
    }

    public MComponent getRenderer() {
        JTree tree = getTreeComponent();
        TreeCellRenderer renderer = (TreeCellRenderer) eventQueueRunner.invoke(tree, "getCellRenderer");
        if (renderer == null)
            return null;
        boolean isSelected = eventQueueRunner.invokeBoolean(tree, "isRowSelected", new Object[] { Integer.valueOf(row) },
                new Class[] { Integer.TYPE });
        boolean isExpanded = eventQueueRunner.invokeBoolean(tree, "isExpanded", new Object[] { Integer.valueOf(row) },
                new Class[] { Integer.TYPE });
        TreePath treePath = (TreePath) eventQueueRunner.invoke(tree, "getPathForRow", new Object[] { Integer.valueOf(row) },
                new Class[] { Integer.TYPE });
        if (treePath == null)
            return null;
        boolean isLeaf = false;
        Component rendererComponent = renderer.getTreeCellRendererComponent(tree, treePath.getLastPathComponent(), isSelected,
                isExpanded, isLeaf, row, true);
        if (rendererComponent == null)
            return null;
        return finder.getMComponentByComponent(rendererComponent, "doesn't matter", null);
    }
View Full Code Here

    if ( value instanceof DefaultMutableTreeNode ) {
      //noinspection AssignmentToMethodParameter
      value = ( ( DefaultMutableTreeNode ) value ).getUserObject();
    }

    TreeCellRenderer renderer = delegates.get( value.getClass() );
    if ( renderer == null ) {
      throw new IllegalArgumentException( "No renderer found for " + value.getClass().getName() );
    }
    return renderer.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, hasFocus );
  }
View Full Code Here

    public TreeCellRenderer getCellRenderer() {
        return cellRenderer;
    }

    public void setCellRenderer(TreeCellRenderer renderer) {
        TreeCellRenderer oldValue = cellRenderer;
        cellRenderer = renderer;
        firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, renderer);
    }
View Full Code Here

        } else {   
            super.setUI(UIManager.getUI(this));
        }

        // Inform the cell renderer since it will behave slightly differently for the banded look and feel
        TreeCellRenderer cellRenderer = getCellRenderer();
        if (cellRenderer instanceof ExplorerCellRenderer) {
            ((ExplorerCellRenderer)cellRenderer).setBandedLookAndFeel(useBandedLookAndFeel);
        }
    }
View Full Code Here

     * Installs appropriate renderer to the tree to highlight search results.
     * @param tree
     */
    private void installRenderer(final UtilTree tree) {
        // Wrap the existing cell renderer with a search tree cell renderer
        TreeCellRenderer renderer = tree.getCellRenderer();
        if (!(renderer instanceof SearchableTreeCellRenderer)) {
            tree.setCellRenderer(SearchableTreeCellRenderer.create(renderer));
        }
       
        // Install a listener that listens for cell renderer changes
        tree.addPropertyChangeListener(
                JTree.CELL_RENDERER_PROPERTY,
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                        TreeCellRenderer renderer = (TreeCellRenderer) evt.getNewValue();
                        tree.setCellRenderer(SearchableTreeCellRenderer.create(renderer));
                    }
                }
        );
    }
View Full Code Here

        // Trim any leading and trailing spaces from the search substring
        searchSubstring = searchSubstring.trim();

        // Set the search string in the renderer so that the renderer knows what to highlight
        TreeCellRenderer renderer = tree.getCellRenderer();
        if (renderer instanceof SearchableTreeCellRenderer) {
            ((SearchableTreeCellRenderer) renderer).setSearchString(searchSubstring);
        }
       
        try {
View Full Code Here

        return ENABLED | SELECTED;
    }

    @Override
    protected TreeCellEditor createDefaultCellEditor() {
        TreeCellRenderer renderer = tree.getCellRenderer();
        DefaultTreeCellEditor editor;

        if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
            editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer)
                                             renderer);
View Full Code Here

            boolean isLeaf;
            Rectangle boundsBuffer = new Rectangle();
            Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0);
            Rectangle bounds;
            TreePath path;
            TreeCellRenderer renderer = tree.getCellRenderer();
            DefaultTreeCellRenderer dtcr = (renderer instanceof
                       DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer)
                       renderer : null;

            configureRenderer(cellContext);
View Full Code Here

TOP

Related Classes of javax.swing.tree.TreeCellRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.