List of usage examples for javax.swing JTree getCellRenderer
public TreeCellRenderer getCellRenderer()
TreeCellRenderer
that is rendering each cell. From source file:Main.java
public static void main(String[] argv) throws Exception { Icon leafIcon = new ImageIcon("leaf.gif"); Icon openIcon = new ImageIcon("open.gif"); Icon closedIcon = new ImageIcon("closed.gif"); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setLeafIcon(leafIcon);//w w w . ja va2 s.co m renderer.setClosedIcon(closedIcon); renderer.setOpenIcon(openIcon); JFrame f = new JFrame(); f.add(new JScrollPane(tree)); f.setSize(300, 300); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Changed Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32)); int rowHeight = tree.getRowHeight(); if (rowHeight <= 0) { tree.setRowHeight(rowHeight - 1); }// w w w . j a v a 2 s.co m Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(Color.blue); renderer.setBackgroundNonSelectionColor(backgroundSelection); // Swap text colors Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(Color.green); renderer.setTextNonSelectionColor(textSelection); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TreeChangedRenderer.java
public static void main(String args[]) { JFrame frame = new JFrame("Changed Renderer"); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32)); int rowHeight = tree.getRowHeight(); if (rowHeight <= 0) { tree.setRowHeight(rowHeight - 1); }/*from w w w . ja va 2s . c om*/ // Swap background colors Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(renderer.getBackgroundNonSelectionColor()); renderer.setBackgroundNonSelectionColor(backgroundSelection); // Swap text colors Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(renderer.getTextNonSelectionColor()); renderer.setTextNonSelectionColor(textSelection); 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(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);/*from w w w . j a v a2s.com*/ DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); TreeCellEditor comboEditor = new DefaultCellEditor(new JTextField()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);/*w ww . ja va2 s.c om*/ DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); String elements[] = { "A", "B", "C", "D" }; JComboBox comboBox = new JComboBox(elements); comboBox.setEditable(true); TreeCellEditor comboEditor = new DefaultCellEditor(comboBox); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from ww w . j a va2s . c om DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); System.out.println(comboEditor.getClickCountToStart()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from ww w .j ava 2s . c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.cancelCellEditing(); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);// w w w . j a va 2 s . co m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.setClickCountToStart(3); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);/*from w w w . j a va 2s .c o m*/ DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); System.out.println(comboEditor.getComponent()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from w w w. j av a2 s .c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.stopCellEditing(); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }