javax.swing.tree.DefaultTreeCellRenderer Java Examples

The following examples show how to use javax.swing.tree.DefaultTreeCellRenderer. 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: TreeBuilder.java    From DiskBrowser with GNU General Public License v3.0 6 votes vote down vote up
private void setDiskIcon (String iconName)
// ---------------------------------------------------------------------------------//
{
  URL url = this.getClass ().getResource (iconName);
  if (url != null)
  {
    ImageIcon icon = new ImageIcon (url);
    DefaultTreeCellRenderer renderer =
        (DefaultTreeCellRenderer) tree.getCellRenderer ();
    renderer.setLeafIcon (icon);
    tree.setCellRenderer (renderer);
    tree.setRowHeight (18);
  }
  else
    System.out.println ("Failed to set the disk icon : " + iconName);
}
 
Example #2
Source File: DarkTreeCellRendererDelegate.java    From darklaf with MIT License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value,
                                              final boolean selected, final boolean expanded,
                                              final boolean leaf, final int row, final boolean hasFocus) {
    boolean isFocused = DarkUIUtil.hasFocus(tree);
    Object unwrapped = unwrapBooleanIfPossible(value);
    Component renderer;
    if (unwrapped instanceof Boolean && isBooleanRenderingEnabled(tree)) {
        Component comp = getBooleanRenderer(tree).getTreeCellRendererComponent(tree, value, selected, expanded,
                                                                               leaf, row, isFocused);
        rendererComponent.setComponentOrientation(tree.getComponentOrientation());
        comp.setComponentOrientation(tree.getComponentOrientation());
        comp.setFont(tree.getFont());
        rendererComponent.setRenderer(this);
        rendererComponent.setRenderComponent(comp);
        renderer = rendererComponent;
    } else {
        if (getDelegate() instanceof DefaultTreeCellRenderer) {
            ((DefaultTreeCellRenderer) getDelegate()).setIcon(null);
            ((DefaultTreeCellRenderer) getDelegate()).setDisabledIcon(null);
        }
        renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, isFocused);
    }
    CellUtil.setupTreeForeground(renderer, tree, selected);
    return renderer;
}
 
Example #3
Source File: NewsTreeCellRenderer.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,boolean isLeaf, int row, boolean focused) {
	JLabel c = (JLabel)new DefaultTreeCellRenderer().getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);

	if (((DefaultMutableTreeNode) value).getUserObject() instanceof MagicNews) {
		try {
			c.setIcon(((MagicNews) ((DefaultMutableTreeNode) value).getUserObject()).getProvider().getIcon());
		}
		catch(Exception e)
		{
			c.setIcon(null);
		}

	}

	if (((DefaultMutableTreeNode) value).getUserObject() instanceof String)
		c.setIcon(MTGConstants.ICON_NEWS);

	return c;
}
 
Example #4
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Inits the IR tree.
 */
private void initIRTree() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(noIndexReposLabel);
  DefaultTreeModel model = new DefaultTreeModel(root);
  this.indexTree = new JTree(model);
  this.indexTree.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 2));
  // Only one node can be selected at any one time.
  this.indexTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  this.indexTree.addTreeSelectionListener(new IndexTreeSelectionListener(this));
  // No icons.
  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setLeafIcon(null);
  // cellRenderer.setIcon(null);
  cellRenderer.setClosedIcon(null);
  cellRenderer.setOpenIcon(null);
  this.indexTree.setCellRenderer(cellRenderer);
}
 
Example #5
Source File: AnnotationFeaturesViewer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Populate.
 *
 * @param analysisEngine the analysis engine
 * @param aeMetaData the ae meta data
 */
public void populate(AnalysisEngine analysisEngine, AnalysisEngineMetaData aeMetaData) {
  tree = generateTreeView(analysisEngine, aeMetaData);

  tree.setDragEnabled(true); // To allow drag to stylemap table.
  tree.setRootVisible(false);
  tree.setShowsRootHandles(true); // Displays node expansion glyphs.

  TreeSelectionModel selectionModel = tree.getSelectionModel();
  selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setLeafIcon(null);
  cellRenderer.setClosedIcon(null);
  cellRenderer.setOpenIcon(null);
  tree.setCellRenderer(cellRenderer);

  scrollPane.getViewport().add(tree, null);
}
 
Example #6
Source File: ExplainDialogFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private JTree createExplanationTree() {
  DefaultMutableTreeNode top = createNode(explanation);
  traverse(top, explanation.getDetails());

  JTree tree = new JTree(top);
  tree.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
  renderer.setOpenIcon(null);
  renderer.setClosedIcon(null);
  renderer.setLeafIcon(null);
  tree.setCellRenderer(renderer);
  // expand all nodes
  for (int row = 0; row < tree.getRowCount(); row++) {
    tree.expandRow(row);
  }
  return tree;
}
 
Example #7
Source File: JTreeTable.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
@Override
public void updateUI ()
{
    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"));
    }
}
 
Example #8
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * updateUI is overridden to set the colors
 * of the Trees renderer to match that of the table.
 **/
@Override
public void updateUI()
{
	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);
		dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground")); //$NON-NLS-1$
		dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground")); //$NON-NLS-1$
	}
}
 
Example #9
Source File: TreePanel.java    From chipster with MIT License 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree,
        Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    DataItem element = (DataItem) node.getUserObject();

    DefaultTreeCellRenderer renderer = 
    	(DefaultTreeCellRenderer)super.getTreeCellRendererComponent(tree, value, selected, 
    			expanded,leaf, row, hasFocus);
    
    renderer.setIcon(application.getIconFor(element));
    renderer.setText(element.toString() + " ");
   
  return this;
}
 
Example #10
Source File: SeaGlassTreeUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void configureRenderer(SeaGlassContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) renderer;
        SeaGlassStyle style = (SeaGlassStyle)context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example #11
Source File: CheckTreeCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf,
                                              int row, boolean hasFocus) {
    // Get CheckTreeNode from current Node
    CheckTreeNode treeNode = (value instanceof CheckTreeNode) ? (CheckTreeNode) value : null;

    // Update UI
    if (treeRendererComponent != null) {
        remove(treeRendererComponent);
    }

    if (treeNode != null) {
        checkBox.setVisible(!persistentRenderer);
        setupCellRendererIcon((DefaultTreeCellRenderer) treeRenderer, treeNode.getIcon());
    } else {
        checkBox.setVisible(false);
        setupCellRendererIcon((DefaultTreeCellRenderer) treeRenderer, null);
    }

    treeRendererComponent = treeRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    add(treeRendererComponent, BorderLayout.CENTER);

    // Return if no path or not a CheckTreeNode
    if (treeNode == null) {
        return this;
    }

    // If tree model supports checking (uses CheckTreeNodes), setup CheckBox
    if (treeNode.isFullyChecked()) {
        setupCheckBox(Boolean.TRUE);
    } else {
        setupCheckBox(treeNode.isPartiallyChecked() ? null : Boolean.FALSE);
    }

    return this;
}
 
Example #12
Source File: SynthTreeUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void configureRenderer(SynthContext context) {
    TreeCellRenderer renderer = tree.getCellRenderer();

    if (renderer instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
        SynthStyle style = context.getStyle();

        context.setComponentState(ENABLED | SELECTED);
        Color color = r.getTextSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setTextSelectionColor(style.getColor(
                                 context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundSelectionColor();
        if (color == null || (color instanceof UIResource)) {
            r.setBackgroundSelectionColor(style.getColor(
                                    context, ColorType.TEXT_BACKGROUND));
        }

        context.setComponentState(ENABLED);
        color = r.getTextNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setTextNonSelectionColor(style.getColorForState(
                                    context, ColorType.TEXT_FOREGROUND));
        }
        color = r.getBackgroundNonSelectionColor();
        if (color == null || color instanceof UIResource) {
            r.setBackgroundNonSelectionColor(style.getColorForState(
                              context, ColorType.TEXT_BACKGROUND));
        }
    }
}
 
Example #13
Source File: SynthTreeUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected TreeCellEditor createDefaultCellEditor() {
    TreeCellRenderer renderer = tree.getCellRenderer();
    DefaultTreeCellEditor editor;

    if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
        editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer)
                                         renderer);
    }
    else {
        editor = new SynthTreeCellEditor(tree, null);
    }
    return editor;
}
 
Example #14
Source File: OptionGroupUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a new option tree.
 *
 * @param dtm The tree model.
 */
public OptionTree(DefaultTreeModel dtm) {
    super(dtm);

    DefaultTreeCellRenderer renderer
        = (DefaultTreeCellRenderer)getCellRenderer();
    renderer.setBackgroundNonSelectionColor(bgColor);
}
 
Example #15
Source File: ModelsPanel.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
    treeModel.setRoot(createRoot());

    tree = new JTree(treeModel) {
        @Override
        public TreeCellRenderer getCellRenderer() {
            TreeCellRenderer renderer = super.getCellRenderer();
            if (renderer == null)
                return null;
            ((DefaultTreeCellRenderer) renderer).setLeafIcon(new ImageIcon(
                    getClass().getResource("/images/function.png")));
            return renderer;
        }
    };

    tree.setCellRenderer(new Renderer());

    tree.setEditable(true);

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if ((e.getButton() == MouseEvent.BUTTON1)
                    && (e.getClickCount() == 2)) {
                openDiagram();
            }
        }

    });

    tree.setRootVisible(true);

    JScrollPane pane = new JScrollPane();
    pane.setViewportView(tree);
    this.add(pane, BorderLayout.CENTER);
}
 
Example #16
Source File: bug7142955.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.put("Tree.rendererFillBackground", Boolean.FALSE);
    UIManager.put("Tree.textBackground", TEST_COLOR);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            int w = 200;
            int h = 100;

            BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

            Graphics g = image.getGraphics();

            g.setColor(Color.WHITE);
            g.fillRect(0, 0, image.getWidth(), image.getHeight());

            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

            renderer.setSize(w, h);
            renderer.paint(g);

            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    if (image.getRGB(x, y) == TEST_COLOR.getRGB()) {
                        throw new RuntimeException("Test bug7142955 failed");
                    }
                }
            }

            System.out.println("Test bug7142955 passed.");
        }
    });
}
 
Example #17
Source File: ExtendedCheckTreeMouseSelectionManager.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public ExtendedCheckTreeMouseSelectionManager(JTree tree, boolean selectAll) {
	this.tree = tree;
	selectionModel = new ExtendedCheckTreeSelectionModel(tree.getModel());

	if (selectAll) {
		selectionModel.addSelectionPath(tree.getPathForRow(0));
	}

	tree.setCellRenderer(new ExtendedCheckTreeCellRenderer(new DefaultTreeCellRenderer(), selectionModel));
	tree.addMouseListener(this);
	selectionModel.addTreeSelectionListener(this);
}
 
Example #18
Source File: GroupedBandChoosingStrategy.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public JPanel createCheckersPane() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    Map<String, Integer> groupNodeMap = initGrouping(root);
    List<TreePath> selectedPaths = new ArrayList<>();
    addBandCheckBoxes(root, selectedPaths, groupNodeMap);
    addTiePointGridCheckBoxes(root, selectedPaths, groupNodeMap);
    removeEmptyGroups(root, groupNodeMap);

    TreeModel treeModel = new DefaultTreeModel(root);

    checkBoxTree = new CheckBoxTree(treeModel);
    checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()]));
    checkBoxTree.setRootVisible(false);
    checkBoxTree.setShowsRootHandles(true);
    checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateCheckBoxStates();
        }
    });
    final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer();
    renderer.setFont(SMALL_ITALIC_FONT);
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    Color color = new Color(240, 240, 240);
    checkBoxTree.setBackground(color);
    renderer.setBackgroundSelectionColor(color);
    renderer.setBackgroundNonSelectionColor(color);
    renderer.setBorderSelectionColor(color);
    renderer.setTextSelectionColor(Color.BLACK);

    GridBagConstraints gbc2 = GridBagUtils.createConstraints("insets.left=4,anchor=WEST,fill=BOTH");
    final JPanel checkersPane = GridBagUtils.createPanel();
    GridBagUtils.addToPanel(checkersPane, checkBoxTree, gbc2, "weightx=1.0,weighty=1.0");
    return checkersPane;
}
 
Example #19
Source File: MainFrame.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a custom tree cell renderer for the navigation tree which sets custom leaf icons.
 * @return a custom tree cell renderer
 */
private TreeCellRenderer createTreeCellRenderer() {
	return new DefaultTreeCellRenderer() {
		public Component getTreeCellRendererComponent( final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus ) {
			super.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, hasFocus );
			final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
			if ( node != newRepAnalNode && node != newMultiRepAnalNode && node != newRepSearchNode && node != emptyRepSourceNode && node != emptyRepListNode && node != pluginsInfoNode ) {
				if ( node == sc2AutoRepsRepSourceNode || node == autoSavedRepsRepSourceNode )
					setIcon( Icons.FOLDER_BOOKMARK );
				else if ( node == startPageNode )
					setIcon( Icons.NEWSPAPER );
				else {
					final TreeNode parentNode = node.getParent();
					if ( parentNode == repAnalNode )
						setIcon( Icons.CHART );
					else if ( parentNode == multiRepAnalNode )
						setIcon( Icons.CHART_UP_COLOR );
					else if ( parentNode == repSearchNode )
						setIcon( Icons.BINOCULAR );
					else if ( parentNode == repSourcesNode )
						setIcon( Icons.FOLDERS_STACK );
					else if ( parentNode == repListsNode )
						setIcon( Icons.TABLE_EXCEL );
					else if ( parentNode == pluginsNode )
						setIcon( Icons.PUZZLE );
				}
			}
			return this;
		};
	};
}
 
Example #20
Source File: DocumentViewPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a cell renderer for the tree view.
 *
 * @param delegate delegating/original tree renderer.
 * @return call renderer for the tree view.
 */
private TreeCellRenderer createTreeCellRenderer(final TreeCellRenderer delegate) {
    return new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            return delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        }
    };
}
 
Example #21
Source File: SynthTreeUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected TreeCellEditor createDefaultCellEditor() {
    TreeCellRenderer renderer = tree.getCellRenderer();
    DefaultTreeCellEditor editor;

    if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
        editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer)
                                         renderer);
    }
    else {
        editor = new SynthTreeCellEditor(tree, null);
    }
    return editor;
}
 
Example #22
Source File: DomPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a cell renderer for the DOM tree.
 * 
 * @param delegate delegating/original tree renderer.
 * @return call renderer for the DOM tree.
 */
private TreeCellRenderer createTreeCellRenderer(final TreeCellRenderer delegate) {
    Color origColor = UIManager.getColor("Tree.selectionBackground"); // NOI18N
    Color color = origColor.brighter().brighter();
    if (color.equals(Color.WHITE)) { // Issue 217127
        color = origColor.darker();
    }
    // Color used for hovering highlight
    final Color hoverColor = color;
    final boolean nimbus = "Nimbus".equals(UIManager.getLookAndFeel().getID()); // NOI18N
    final JPanel nimbusPanel = nimbus ? new JPanel(new BorderLayout()) : null;
    return new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            JComponent component;
            if (!selected && isHighlighted(value)) {
                component = (JComponent)delegate.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, hasFocus);
                if (nimbus) {
                    nimbusPanel.removeAll();
                    nimbusPanel.add(component);
                    component = nimbusPanel;
                }
                component.setBackground(hoverColor);
                component.setOpaque(true);
            } else {
                component = (JLabel)delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
            }
            return component;
        }
    };
}
 
Example #23
Source File: TreeViewCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Construct a cell editor.
* @param tree the tree
*/
public TreeViewCellEditor(JTree tree) {
    //Use a dummy DefaultTreeCellEditor - we'll set up the correct
    //icon when we fetch the editor component (see EOF).  Not sure
    //it's wildly vaulable to subclass DefaultTreeCellEditor here - 
    //we override most everything
    super(tree, new DefaultTreeCellRenderer());

    // deal with selection if already exists
    if (tree.getSelectionCount() == 1) {
        lastPath = tree.getSelectionPath();
    }

    addCellEditorListener(this);
}
 
Example #24
Source File: MethodsCountPanel.java    From android-classyshark with Apache License 2.0 5 votes vote down vote up
private void setup() {
    this.setLayout(new BorderLayout());
    treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(null));
    jTree = new JTree(treeModel);
    jTree.setRootVisible(false);
    jTree.setCellRenderer(new CellRenderer());
    theme.applyTo(jTree);

    DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer();

    cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20));
    jTree.setCellRenderer(cellRenderer);
    jTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            Object selection = jTree.getLastSelectedPathComponent();
            DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)selection;
            ClassNode node = (ClassNode) defaultMutableTreeNode.getUserObject();
            viewerController.onSelectedMethodCount(node);
        }
    });

    JScrollPane jScrollPane = new JScrollPane(jTree);
    this.setBorder(new EmptyBorder(0,0,0,0));
    this.add(jScrollPane, BorderLayout.CENTER);
    theme.applyTo(jScrollPane);

    jTree.setDragEnabled(true);
    jTree.setTransferHandler(new FileTransferHandler(viewerController));
}
 
Example #25
Source File: bug7142955.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.put("Tree.rendererFillBackground", Boolean.FALSE);
    UIManager.put("Tree.textBackground", TEST_COLOR);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            int w = 200;
            int h = 100;

            BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

            Graphics g = image.getGraphics();

            g.setColor(Color.WHITE);
            g.fillRect(0, 0, image.getWidth(), image.getHeight());

            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

            renderer.setSize(w, h);
            renderer.paint(g);

            for (int y = 0; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    if (image.getRGB(x, y) == TEST_COLOR.getRGB()) {
                        throw new RuntimeException("Test bug7142955 failed");
                    }
                }
            }

            System.out.println("Test bug7142955 passed.");
        }
    });
}
 
Example #26
Source File: CodeEditor.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
protected DefaultTreeCellRenderer makeRenderer() {
	DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
	renderer.setLeafIcon(null);
	renderer.setOpenIcon(null);
	renderer.setClosedIcon(null);
	return renderer;
}
 
Example #27
Source File: PerformanceMonitor.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void refreshFrameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshFrameActionPerformed
    componentHierarchy.setModel(new ComponentTreeModel(Display.getInstance().getCurrent()));
    componentHierarchy.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            String s = value.toString();
            if(value instanceof Component) {
                s = ((Component)value).getUIID() + ": " + s;
            }
            return super.getTreeCellRendererComponent(tree, s, sel, expanded, leaf, row, hasFocus); //To change body of generated methods, choose Tools | Templates.
        }
        
    });
    
    Display.getInstance().callSerially(new Runnable() {
        public void run() {
            trackDrawing = true;
            Display.getInstance().getCurrent().repaint();
            Display.getInstance().callSerially(new Runnable() {
                public void run() {
                    // data collected
                    trackDrawing = false;
                    renderedItems.setModel(createTableModel());
                }
            });
        }
    });
}
 
Example #28
Source File: SynthTreeUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected TreeCellEditor createDefaultCellEditor() {
    TreeCellRenderer renderer = tree.getCellRenderer();
    DefaultTreeCellEditor editor;

    if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
        editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer)
                                         renderer);
    }
    else {
        editor = new SynthTreeCellEditor(tree, null);
    }
    return editor;
}
 
Example #29
Source File: SwingGui.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Initializes a tree for this tree table.
 */
public JTree resetTree(TreeTableModel treeTableModel) {
    tree = new TreeTableCellRenderer(treeTableModel);

    // Install a tableModel representing the visible rows in the tree.
    super.setModel(new TreeTableModelAdapter(treeTableModel, tree));

    // Force the JTable and JTree to share their row selection models.
    ListToTreeSelectionModelWrapper selectionWrapper = new
        ListToTreeSelectionModelWrapper();
    tree.setSelectionModel(selectionWrapper);
    setSelectionModel(selectionWrapper.getListSelectionModel());

    // Make the tree and table row heights the same.
    if (tree.getRowHeight() < 1) {
        // Metal looks better like this.
        setRowHeight(18);
    }

    // Install the tree editor renderer and editor.
    setDefaultRenderer(TreeTableModel.class, tree);
    setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor());
    setShowGrid(true);
    setIntercellSpacing(new Dimension(1,1));
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)tree.getCellRenderer();
    r.setOpenIcon(null);
    r.setClosedIcon(null);
    r.setLeafIcon(null);
    return tree;
}
 
Example #30
Source File: SynthTreeUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected TreeCellEditor createDefaultCellEditor() {
    TreeCellRenderer renderer = tree.getCellRenderer();
    DefaultTreeCellEditor editor;

    if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) {
        editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer)
                                         renderer);
    }
    else {
        editor = new SynthTreeCellEditor(tree, null);
    }
    return editor;
}