Java Code Examples for javax.swing.tree.DefaultTreeCellRenderer#setFont()
The following examples show how to use
javax.swing.tree.DefaultTreeCellRenderer#setFont() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodsCountPanel.java From android-classyshark with Apache License 2.0 | 5 votes |
private void setup() { this.setLayout(new BorderLayout()); treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(null)); jTree = new JTree(treeModel); jTree.setRootVisible(false); jTree.setCellRenderer(new CellRenderer()); theme.applyTo(jTree); DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer(); cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20)); jTree.setCellRenderer(cellRenderer); jTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { Object selection = jTree.getLastSelectedPathComponent(); DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)selection; ClassNode node = (ClassNode) defaultMutableTreeNode.getUserObject(); viewerController.onSelectedMethodCount(node); } }); JScrollPane jScrollPane = new JScrollPane(jTree); this.setBorder(new EmptyBorder(0,0,0,0)); this.add(jScrollPane, BorderLayout.CENTER); theme.applyTo(jScrollPane); jTree.setDragEnabled(true); jTree.setTransferHandler(new FileTransferHandler(viewerController)); }
Example 2
Source File: GroupedBandChoosingStrategy.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public JPanel createCheckersPane() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); Map<String, Integer> groupNodeMap = initGrouping(root); List<TreePath> selectedPaths = new ArrayList<>(); addBandCheckBoxes(root, selectedPaths, groupNodeMap); addTiePointGridCheckBoxes(root, selectedPaths, groupNodeMap); removeEmptyGroups(root, groupNodeMap); TreeModel treeModel = new DefaultTreeModel(root); checkBoxTree = new CheckBoxTree(treeModel); checkBoxTree.getCheckBoxTreeSelectionModel().setSelectionPaths(selectedPaths.toArray(new TreePath[selectedPaths.size()])); checkBoxTree.setRootVisible(false); checkBoxTree.setShowsRootHandles(true); checkBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { updateCheckBoxStates(); } }); final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) checkBoxTree.getActualCellRenderer(); renderer.setFont(SMALL_ITALIC_FONT); renderer.setLeafIcon(null); renderer.setOpenIcon(null); renderer.setClosedIcon(null); Color color = new Color(240, 240, 240); checkBoxTree.setBackground(color); renderer.setBackgroundSelectionColor(color); renderer.setBackgroundNonSelectionColor(color); renderer.setBorderSelectionColor(color); renderer.setTextSelectionColor(Color.BLACK); GridBagConstraints gbc2 = GridBagUtils.createConstraints("insets.left=4,anchor=WEST,fill=BOTH"); final JPanel checkersPane = GridBagUtils.createPanel(); GridBagUtils.addToPanel(checkersPane, checkBoxTree, gbc2, "weightx=1.0,weighty=1.0"); return checkersPane; }
Example 3
Source File: ClassExplorerDialog.java From jar-explorer with Apache License 2.0 | 4 votes |
/** * COnstructs an instance * * @param owner - top level frame * @param classInformation - instance */ public ClassExplorerDialog(Frame owner, ClassInformation classInformation) { super(owner, classInformation.getJarFileName() + ":" + classInformation.getClassPath(), false); getContentPane().setLayout(new BorderLayout()); //build center panel - tree DefaultMutableTreeNode classNode; DefaultMutableTreeNode constructorsNode; DefaultMutableTreeNode interfacesNode; DefaultMutableTreeNode fieldsNode; DefaultMutableTreeNode methodsNode; DefaultMutableTreeNode modifiersNode; DefaultMutableTreeNode root = new DefaultMutableTreeNode("<html><font color='blue'>Class:</font>" + classInformation.getClassName() + "</html>"); root.add(classNode = new DefaultMutableTreeNode("<html><font color='blue'>General Class Information</font></html>")); root.add(interfacesNode = new DefaultMutableTreeNode("<html><font color='blue'>Implemented Interfaces</font></html>")); root.add(constructorsNode = new DefaultMutableTreeNode("<html><font color='blue'>Constructors</font></html>")); root.add(fieldsNode = new DefaultMutableTreeNode("<html><font color='blue'>Fields</font></html>")); root.add(methodsNode = new DefaultMutableTreeNode("<html><font color='blue'>Methods</font></html>")); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)tree.getCellRenderer(); renderer.setFont(new Font("Monospaced", Font.PLAIN, 14)); classNode.add(new DefaultMutableTreeNode("<html><font color='blue'>Jar File: </font>" + classInformation.getJarFileName() + "</html>")); classNode.add(new DefaultMutableTreeNode("<html><font color='blue'>Superclass: </font>" + classInformation.getSuperclass() + "</html>")); classNode.add(modifiersNode = new DefaultMutableTreeNode("<html><font color='blue'>Modifiers:</font>" + classInformation.getModifiers() + "</html>")); ((DefaultTreeModel)tree.getModel()).setRoot(root); //interfaces String[] interfacesArray = classInformation.getInterfaces(); for (int i = 0; i < interfacesArray.length; i++) { String interfaceName = interfacesArray[i]; interfacesNode.add(new DefaultMutableTreeNode(interfaceName)); } //constructors ArrayList constructorList = classInformation.getConstructors(); for (int i = 0; i < constructorList.size(); i++) { String constructor = (String) constructorList.get(i); constructorsNode.add(new DefaultMutableTreeNode(constructor)); } //methods ArrayList methodsList = classInformation.getMethods(); for (int i = 0; i < methodsList.size(); i++) { String method = (String) methodsList.get(i); methodsNode.add(new DefaultMutableTreeNode(method)); } //fields String[] fieldsList = classInformation.getFields(); for (int i = 0; i < fieldsList.length; i++) { String field = fieldsList[i]; fieldsNode.add(new DefaultMutableTreeNode(field)); } //build south panel JPanel southPanel = new JPanel(); JButton closeB = new JButton("Close"); southPanel.add(closeB); closeB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); //build mail panel getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER); getContentPane().add(southPanel, BorderLayout.SOUTH); }
Example 4
Source File: FilesTree.java From android-classyshark with Apache License 2.0 | 4 votes |
private void configureJTree(final JTree jTree) { jTree.setRootVisible(false); DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) jTree.getCellRenderer(); cellRenderer.setFont(new Font("Monospaced", Font.PLAIN, 20)); jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { Object selection = jTree.getLastSelectedPathComponent(); if (selection == null) return; DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) selection; if (selection.toString().endsWith(".dex")) { FilesTree.this.viewerController.onSelectedClassName( (String) defaultMutableTreeNode.getUserObject()); return; } if (selection.toString().endsWith(".jar")) { FilesTree.this.viewerController.onSelectedClassName( (String) defaultMutableTreeNode.getUserObject()); return; } if (selection.toString().endsWith(".apk")) { FilesTree.this.viewerController.onSelectedClassName( (String) defaultMutableTreeNode.getUserObject()); return; } if (selection.toString().endsWith(".so")) { FilesTree.this.viewerController.onSelectedClassName( (String) defaultMutableTreeNode.getUserObject()); return; } if (!defaultMutableTreeNode.isLeaf()) return; if (FilesTree.this.viewerController != null) { if (defaultMutableTreeNode.getUserObject() instanceof String) { FilesTree.this.viewerController.onSelectedClassName( (String) defaultMutableTreeNode.getUserObject()); } else { FilesTree.this.viewerController.onSelectedClassName( ((NodeInfo) defaultMutableTreeNode.getUserObject()).fullname); } } } }); }