List of usage examples for javax.swing JTree setFont
@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.") public void setFont(Font font)
From source file:ComponentTree.java
/** * This main() method demonstrates the use of the ComponentTree class: it * puts a ComponentTree component in a Frame, and uses the ComponentTree to * display its own GUI hierarchy. It also adds a TreeSelectionListener to * display additional information about each component as it is selected *//* w w w. j a va 2 s. c o m*/ public static void main(String[] args) { // Create a frame for the demo, and handle window close requests JFrame frame = new JFrame("ComponentTree Demo"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Create a scroll pane and a "message line" and add them to the // center and bottom of the frame. JScrollPane scrollpane = new JScrollPane(); final JLabel msgline = new JLabel(" "); frame.getContentPane().add(scrollpane, BorderLayout.CENTER); frame.getContentPane().add(msgline, BorderLayout.SOUTH); // Now create the ComponentTree object, specifying the frame as the // component whose tree is to be displayed. Also set the tree's font. JTree tree = new ComponentTree(frame); tree.setFont(new Font("SansSerif", Font.BOLD, 12)); // Only allow a single item in the tree to be selected at once tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // Add an event listener for notifications when // the tree selection state changes. tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { // Tree selections are referred to by "path" // We only care about the last node in the path TreePath path = e.getPath(); Component c = (Component) path.getLastPathComponent(); // Now we know what component was selected, so // display some information about it in the message line if (c.isShowing()) { Point p = c.getLocationOnScreen(); msgline.setText("x: " + p.x + " y: " + p.y + " width: " + c.getWidth() + " height: " + c.getHeight()); } else { msgline.setText("component is not showing"); } } }); // Now that we've set up the tree, add it to the scrollpane scrollpane.setViewportView(tree); // Finally, set the size of the main window, and pop it up. frame.setSize(600, 400); frame.setVisible(true); }
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 ww w .j a v a 2s . c om*/ } 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); }