List of usage examples for javax.swing JTree getFont
@Transient
public Font getFont()
From source file:ws.moor.bt.grapher.Grapher.java
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Please specify a tab-separated values file"); System.exit(1);/*from w ww.ja v a 2 s .co m*/ } File file = new File(args[0]); final CSVMapCollector collector = new CSVMapCollector( new CSVSkipFilter(new CSVInputStream(new FileInputStream(file)), 0 * 1000)); JFrame window = new JFrame("Grapher"); window.setSize(1100, 800); window.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(null); List<String> possibleNames = collector.getAvailableStreams(); Collections.sort(possibleNames); TreeNode root = convertToTree(possibleNames); final JTree tree = new JTree(root); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { List<String> names = new ArrayList<String>(); final TreePath[] paths = tree.getSelectionModel().getSelectionPaths(); if (paths == null) { chartPanel.setChart(null); return; } for (TreePath path : paths) { Object lastPath = path.getLastPathComponent(); if (lastPath instanceof DefaultMutableTreeNode) { Object value = ((DefaultMutableTreeNode) lastPath).getUserObject(); if (value instanceof NodeValue) { names.add(value.toString()); } } } chartPanel.setChart(createChart(collector, names.toArray(new String[names.size()]))); } }); Font font = tree.getFont(); tree.setFont(font.deriveFont(10.0f)); JScrollPane scrollPane = new JScrollPane(tree); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(scrollPane); splitPane.setRightComponent(chartPanel); splitPane.setDividerLocation(200); window.setContentPane(splitPane); window.setVisible(true); }
From source file:Main.java
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel l = (JLabel) renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);//from w ww . jav a2s . c o m if (value instanceof DefaultMutableTreeNode) { check.setEnabled(tree.isEnabled()); check.setFont(tree.getFont()); Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof CheckBoxNode) { CheckBoxNode node = (CheckBoxNode) userObject; l.setText(node.text); check.setSelected(node.selected); } p.add(l); return p; } return l; }
From source file:AncestorTree.java
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object obj = node.getUserObject(); setText(obj.toString());/*w w w. j av a 2 s. com*/ if (obj instanceof IconData) { IconData idata = (IconData) obj; if (expanded) setIcon(idata.getOpenIcon()); else setIcon(idata.getIcon()); } else setIcon(null); setFont(tree.getFont()); setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor); setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor); m_selected = sel; return this; }
From source file:AncestorTree.java
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object obj = node.getUserObject(); if (obj instanceof IconData) { IconData idata = (IconData) obj; m_item = idata;/* w w w.ja v a 2 s . co m*/ // Reserve some more space... setText(idata.toString() + " "); setIcon(idata.m_icon); setFont(tree.getFont()); return this; } } // We don't support other objects... return null; }
From source file:FileTree3.java
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object obj = node.getUserObject(); setText(obj.toString());/*from ww w . j av a 2s. com*/ if (obj instanceof Boolean) setText("Retrieving data..."); if (obj instanceof IconData) { IconData idata = (IconData) obj; if (expanded) setIcon(idata.getExpandedIcon()); else setIcon(idata.getIcon()); } else setIcon(null); setFont(tree.getFont()); setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor); setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor); m_selected = sel; return this; }