List of usage examples for javax.swing JTree repaint
public void repaint()
From source file:CustomTreeCellRenderer.java
public static void main(String[] args) { ImageIcon iconWhite = new ImageIcon("white.jpg"); ImageIcon iconBlack = new ImageIcon("black.jpg"); ;//ww w. j a v a2 s . c om JFrame frame = new JFrame(); frame.setContentPane(new JPanel(new BorderLayout())); JTree tree = new JTree(); frame.getContentPane().add(tree); CustomTreeCellRenderer renderer = new CustomTreeCellRenderer(); renderer.setRendererIcon(iconWhite); tree.setCellRenderer(renderer); JPanel panelButtons = new JPanel(); JButton buttonWhite = new JButton(""); buttonWhite.setIcon(iconWhite); JButton buttonBlack = new JButton(""); buttonBlack.setIcon(iconBlack); buttonBlack.addActionListener(e -> { renderer.setRendererIcon(iconBlack); tree.repaint(); }); panelButtons.add(buttonBlack); panelButtons.add(buttonWhite); frame.getContentPane().add(panelButtons, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); frame.setVisible(true); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserComponent.java
/** * Implemented as specified by the {@link Browser} interface. * @see Browser#setFoundInBrowser(Set)//from w w w . j a va2 s . com */ public void setFoundInBrowser(Set nodes) { if (nodes == null || nodes.size() == 0) { model.setFoundNodes(null); // reset default value. model.setFoundNodeIndex(-1); // reset default value. view.getTreeDisplay().repaint(); return; } List<Object> list = new ArrayList<Object>(nodes.size()); Iterator i = nodes.iterator(); final JTree tree = view.getTreeDisplay(); while (i.hasNext()) list.add(i.next()); Comparator c = new Comparator() { public int compare(Object o1, Object o2) { TreeImageDisplay node1 = (TreeImageDisplay) o1; TreeImageDisplay node2 = (TreeImageDisplay) o2; int i1 = tree.getRowForPath(new TreePath(node1.getPath())); int i2 = tree.getRowForPath(new TreePath(node2.getPath())); return (i1 - i2); } }; Collections.sort(list, c); model.setFoundNodes(list); model.setFoundNodeIndex(0); handleNodeDisplay((TreeImageDisplay) list.get(0)); tree.repaint(); }