Package javax.swing.tree

Examples of javax.swing.tree.DefaultTreeCellRenderer


        private void setupRendererUI() {
            panel = new JPanel();
            panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

            nameRenderer = new DefaultTreeCellRenderer();
            descriptionRenderer = new DefaultTreeCellRenderer();

            panel.add(nameRenderer);
            seperator = Box.createHorizontalStrut(10);
            panel.add(seperator);
            panel.add(descriptionRenderer);
View Full Code Here


      }  
  }

  /** For subclasses to specialize*/
  protected TreeCellRenderer createRenderer() {
    return new DefaultTreeCellRenderer();
  }
View Full Code Here

        helpTree.setRootVisible(false);
        helpTree.setShowsRootHandles(true);
        helpTree.addTreeSelectionListener(this);

        // Renderer
        DefaultTreeCellRenderer  helpTreeRenderer = (DefaultTreeCellRenderer) helpTree.getCellRenderer();
        helpTreeRenderer.setOpenIcon(resources.getIcon("folderIcon"));
        helpTreeRenderer.setClosedIcon(resources.getIcon("folderIcon"));
        helpTreeRenderer.setLeafIcon(resources.getIcon("leafIcon"));

        createHelpContents();


        // Create help search panel

        // search tree
        searchRootTreeNode = new DefaultMutableTreeNode();
        searchTreeModel = new DefaultTreeModel(searchRootTreeNode);
        searchTree = new JTree();
        searchTree.setModel(searchTreeModel);
        searchTree.setRootVisible(false);
        searchTree.setShowsRootHandles(true);
        searchTree.addTreeSelectionListener(this);

        JScrollPane scrollSearchTree = new JScrollPane(searchTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );

        DefaultTreeCellRenderer  searchTreeRenderer = (DefaultTreeCellRenderer) searchTree.getCellRenderer();
        searchTreeRenderer.setOpenIcon(resources.getIcon("folderIcon"));
        searchTreeRenderer.setClosedIcon(resources.getIcon("folderIcon"));
        searchTreeRenderer.setLeafIcon(resources.getIcon("leafIcon"));


        // search field
        JToolBar  toolbar = new JToolBar();
        toolbar.setRollover(true);
View Full Code Here

    private void setupTree() {
        root = new DefaultMutableTreeNode(resources.getString("preferences"));
        topNode = new DefaultMutableTreeNode(resources.getString("preferences"));
        root.add(topNode);

        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
            public Component getTreeCellRendererComponent(JTree tree,
                    Object value, boolean sel, boolean expanded, boolean leaf,
                    int row, boolean hasFocus) {
                super.getTreeCellRendererComponent(tree, value, sel, expanded,
                        leaf, row, hasFocus);

                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                setText(((String) node.getUserObject()).replaceAll("^a\\d+ ",
                        ""));

                return this;
            }
        };
        renderer.setLeafIcon(null);

        Iterator i = prefsDialog.getPanels().keySet().iterator();

        while (i.hasNext()) {
            topNode.add(new DefaultMutableTreeNode((String) i.next()));
View Full Code Here

    public static final Color EXCEPTION_BG_COLOR = Color.red;
   
    private TreeNodeInfo executingNodeInfo;

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        if (value instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
            Object userObject =  defaultMutableTreeNode.getUserObject();
            if (userObject instanceof TreeNodeInfo) {
                TreeNodeInfo treeNodeInfo = (TreeNodeInfo) userObject;

                renderer.setToolTipText(null);

                if ( treeNodeInfo.hasException() ) {
                    renderer.setForeground(EXCEPTION_COLOR);
                    renderer.setBackgroundNonSelectionColor(EXCEPTION_BG_COLOR);
                    String msg = treeNodeInfo.getException().getMessage();
                    renderer.setToolTipText(msg == null ? "Error" : msg);
                } else {
                    renderer.setBackgroundNonSelectionColor(executingNodeInfo == treeNodeInfo ? RUNNING_BG_COLOR : Color.white);
                    if (!sel && executingNodeInfo != treeNodeInfo) {
                        if (treeNodeInfo.getExecutionCount() > 0) {
                            renderer.setForeground(EXECUTED_COLOR);
                        }
                    }
                }

                Icon icon = treeNodeInfo.getIcon();
                if (icon != null) {
                    renderer.setIcon(icon);
                }
            }
        }

        return renderer;
View Full Code Here

        tree = new JTree(topNode);
        tree.setRootVisible(false);
        tree.setShowsRootHandles(true);
        tree.setBorder( new EmptyBorder(5, 5, 5, 5) );
        tree.setCellRenderer(new DefaultTreeCellRenderer() {
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
                if (value instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
                    Object userObject =  defaultMutableTreeNode.getUserObject();
                    if (userObject instanceof TopicInfo) {
                        TopicInfo topicInfo = (TopicInfo) userObject;
                        renderer.setIcon( topicInfo.subtopicCount == 0 ? ResourceManager.HELPTOPIC_ICON : ResourceManager.HELPDIR_ICON );
                    }
                }
                return renderer;
            }
        });
View Full Code Here

      // Must be registered for renderer tooltips to work
      ToolTipManager.sharedInstance().registerComponent(recordTree);

      // Load leaf icon for the tree cell renderer.
      TreeCellRenderer renderer = new DefaultTreeCellRenderer() {
          public Component getTreeCellRendererComponent(JTree tree,
                                                        Object value,
                                                        boolean sel,
                                                        boolean expanded,
                                                        boolean leaf,
View Full Code Here

      super.updateUI();
      // Make the tree's cell renderer use the table's cell selection
      // colors.
      TreeCellRenderer tcr = getCellRenderer();
      if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
        // For 1.1 uncomment this, 1.2 has a bug that will cause an
        // exception to be thrown if the border selection color is
        // null.
        // dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
      }
    }
View Full Code Here

      visibleRow = row;
      setBackground(background);

      TreeCellRenderer tcr = getCellRenderer();
      if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
        if (isSelected) {
          dtcr.setTextSelectionColor(foreground);
          dtcr.setBackgroundSelectionColor(background);
        } else {
          dtcr.setTextNonSelectionColor(foreground);
          dtcr.setBackgroundNonSelectionColor(background);
        }
      }
      return this;
    }
View Full Code Here

        this.jTreeModel = treeModel;
        tree = new JTree(treeModel);
        tree.setRootVisible(false);
        tree.setShowsRootHandles(true);

        DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
        treeRenderer.setClosedIcon(null);
        treeRenderer.setLeafIcon(null);
        treeRenderer.setOpenIcon(null);

        tree.setCellRenderer(treeRenderer);

        tree.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
View Full Code Here

TOP

Related Classes of javax.swing.tree.DefaultTreeCellRenderer

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.