List of usage examples for javax.swing JTree setCellRenderer
@BeanProperty(description = "The TreeCellRenderer that will be used to draw each cell.") public void setCellRenderer(TreeCellRenderer x)
TreeCellRenderer
that will be used to draw each cell. From source file:Main.java
public static void main(String[] args) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("Days"); for (DaysOfTheWeek dotw : DaysOfTheWeek.values()) { root.add(new DefaultMutableTreeNode(dotw)); }/*from w w w. ja v a 2 s . c o m*/ final DefaultTreeModel model = new DefaultTreeModel(root); JTree tree = new JTree(model); tree.setRootVisible(true); tree.setShowsRootHandles(true); ToolTipManager.sharedInstance().registerComponent(tree); tree.setCellRenderer(new MyTreeCellRenderer()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(tree)); f.pack(); f.setVisible(true); }
From source file:BookTree.java
public static void main(String args[]) { JFrame frame = new JFrame("Book Tree"); Book javaBooks[] = { new Book("Core Java 2 Fundamentals", "Cornell/Horstmann", 42.99f), new Book("Taming Java Threads", "Holub", 34.95f), new Book("JavaServer Pages", "Pekowsky", 39.95f) }; Book htmlBooks[] = { new Book("Dynamic HTML", "Goodman", 39.95f), new Book("HTML 4 Bible", "Pfaffenberger/Gutzman", 49.99f) }; Vector javaVector = new NamedVector("Java Books", javaBooks); Vector htmlVector = new NamedVector("HTML Books", htmlBooks); Object rootNodes[] = { javaVector, htmlVector }; Vector rootVector = new NamedVector("Root", rootNodes); JTree tree = new JTree(rootVector); TreeCellRenderer renderer = new BookCellRenderer(); tree.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 300);/* w w w .j a va 2 s . c o m*/ frame.setVisible(true); }
From source file:CustomTreeCellRenderer.java
public static void main(String[] args) { ImageIcon iconWhite = new ImageIcon("white.jpg"); ImageIcon iconBlack = new ImageIcon("black.jpg"); ;//from ww w .ja va 2 s . co m 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:CheckBoxNodeTreeSample.java
public static void main(String args[]) { JFrame frame = new JFrame("CheckBox Tree"); CheckBoxNode accessibilityOptions[] = { new CheckBoxNode("Move system caret with focus/selection changes", false), new CheckBoxNode("Always expand alt text for images", true) }; CheckBoxNode browsingOptions[] = { new CheckBoxNode("Notify when downloads complete", true), new CheckBoxNode("Disable script debugging", true), new CheckBoxNode("Use AutoComplete", true), new CheckBoxNode("Browse in a new process", false) }; Vector accessVector = new NamedVector("Accessibility", accessibilityOptions); Vector browseVector = new NamedVector("Browsing", browsingOptions); Object rootNodes[] = { accessVector, browseVector }; Vector rootVector = new NamedVector("Root", rootNodes); JTree tree = new JTree(rootVector); CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer(); tree.setCellRenderer(renderer); tree.setCellEditor(new CheckBoxNodeEditor(tree)); tree.setEditable(true);/* w w w . j a va 2 s . c o m*/ JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 11, 212, 500); frame.getContentPane().add(scrollPane); JTree tree = new JTree(addNodes(new File("."))); tree.setRootVisible(false);/*from w w w . j ava2 s.c om*/ tree.setShowsRootHandles(true); tree.setBorder(new LineBorder(new Color(0, 0, 0))); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); scrollPane.setViewportView(tree); tree.setCellRenderer(new FileTreeCellRenderer()); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] m = { "A", "B", "C" }; DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Node("Values")); root.add(new DefaultMutableTreeNode(new Node("Value 1", m))); root.add(new DefaultMutableTreeNode(new Node("Value 2", m))); DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(new Node("Value 3", m)); root.add(leaf);//from w ww.j a v a 2s . com leaf.add(new DefaultMutableTreeNode(new Node("Value 3A", m))); leaf.add(new DefaultMutableTreeNode(new Node("Value 3B", m))); JTree tree = new JTree(root); RendererDispatcher rendererDispatcher = new RendererDispatcher(new JComboBox<String>()); RendererDispatcher editorDispatcher = new RendererDispatcher(new JComboBox<String>()); tree.setCellRenderer(rendererDispatcher); tree.setCellEditor(editorDispatcher); tree.setEditable(true); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(tree)); f.setSize(320, 240); f.setVisible(true); }
From source file:OAT.ui.util.UiUtil.java
public static void clearTreeIcon(JTree tree) { DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setOpenIcon(null);//from ww w .j a v a2 s .c om renderer.setClosedIcon(null); //renderer.setLeafIcon(null); tree.setCellRenderer(renderer); }
From source file:Main.java
public static JComponent makeUI() { JTree tree = new JTree(); TreeModel model = tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); Enumeration e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); Object o = node.getUserObject(); if (o instanceof String) { node.setUserObject(new CheckBoxNode((String) o, false)); }//w w w . j av a 2 s . c o m } tree.setEditable(true); tree.setCellRenderer(new CheckBoxNodeRenderer()); tree.setCellEditor(new CheckBoxNodeEditor()); tree.expandRow(0); return new JScrollPane(tree); }
From source file:eu.europa.ec.markt.dss.applet.util.ComponentFactory.java
/** * /*from w ww .j av a 2s. com*/ * @param name * @param model * @param cellRenderer * @return */ public static JTree tree(final String name, final TreeModel model, final TreeCellRenderer cellRenderer) { final JTree tree = new JTree(); tree.setName(name); tree.setModel(model); if (cellRenderer != null) { tree.setCellRenderer(cellRenderer); } return tree; }
From source file:TreeCellRendererImplementation.java
public TreeCellRendererImplementation() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultMutableTreeNode root = new DefaultMutableTreeNode("+"); root.add(new DefaultMutableTreeNode(new Integer(3))); DefaultMutableTreeNode node = new DefaultMutableTreeNode("*"); node.add(new DefaultMutableTreeNode("string")); node.add(new DefaultMutableTreeNode(new Short((short) 5))); root.add(node);/* w w w . j ava2 s . c o m*/ TreeModel tm = new DefaultTreeModel(root); JTree tree = new JTree(tm); tree.setShowsRootHandles(true); tree.setCellRenderer(new MyRenderer()); getContentPane().add(tree, BorderLayout.CENTER); setSize(400, 300); setVisible(true); }