Java 8 JTree - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JTree class.

This code example shows how to use the following methods:getModel, makeVisible, setSelectionPath
		testSelected(); 
	} 
	 
	public void revealFailure(Test failure) {
		JTree tree= fTreeBrowser.getTree();
		TestTreeModel model= (TestTreeModel)tree.getModel();
		Vector vpath= new Vector();
		int index= model.findTest(failure, (Test)model.getRoot(), vpath);
		if (index >= 0) {
			Object[] path= new Object[vpath.size()+1];
			vpath.copyInto(path);
			Object last= path[vpath.size()-1];
			path[vpath.size()]= model.getChild(last, index);
			TreePath selectionPath= new TreePath(path);
			tree.setSelectionPath(selectionPath);
			tree.makeVisible(selectionPath);
		} 
	} 
	 
	public void aboutToStart(Test suite, TestResult result) {
		fTreeBrowser.showTestTree(suite);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addTreeSelectionListener, setCellRenderer, setRootVisible
	public SwingSpyPanel() { 
		setPreferredSize(new Dimension(INITIAL_WIDTH, INITIAL_HEIGHT));
		setLayout(new BorderLayout());
 
		root = new DefaultMutableTreeNode();
		componentTree = new JTree(root);
		componentTree.setRootVisible(false);
		componentTree.setCellRenderer(new SwingComponentRenderer());
		componentTree.addTreeSelectionListener(new CustomSelectionListener());
//		add(new JScrollPane(componentTree), BorderLayout.CENTER); 
 
		detailsData = new JEditorPane();
		detailsData.setBackground(new Color(250, 250, 250));
		detailsData.setForeground(new Color(33, 33, 33));
		detailsData.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 244), 1));
		detailsData.setPreferredSize(new Dimension(150, INITIAL_HEIGHT));
		detailsData.setEditable(false);
		detailsData.setContentType("text/html");
		SwingUtil.enforceJEditorPaneFont(detailsData, font);
		detailsScrollPane = new JScrollPane(detailsData);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPathForLocation, getSelectionCount, isPathSelected, setSelectionPath
        } 
        return row;
    } 
 
    protected TreePath checkTreeSelection(JTree tree, Point p) {
        TreePath path = tree.getPathForLocation(p.x, p.y);
        if (path != null && tree.getSelectionCount() < 2 && !tree.isPathSelected(path)) {
            tree.setSelectionPath(path);
        } 
        return path;
    } 
 
    protected static boolean isDoubleClick(MouseEvent e) {
        return e != null && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2;
    } 
 
    /** 
     * @return the popup menu if defined, {@code null} otherwise. 
     * @since 5884 
     */ 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addTreeSelectionListener, getSelectionModel, setShowsRootHandles
This code example shows how to use the following methods:addTreeSelectionListener, setCellRenderer, setRootVisible, setSelectionModel, setShowsRootHandles
This code example shows how to use the following methods:addTreeSelectionListener, getSelectionModel, setEditable, setModel, setRootVisible
	/** 
	 * The constructor constructs the <tt>JTree</tt>, the <tt>TreeModel</tt>, 
	 * and the <tt>JScrollPane</tt>. 
	 */ 
	OptionsTreeManager() { 
		TREE = new JTree();
		TREE.setEditable(false);
		TREE.setShowsRootHandles(true);	
		TREE.setRootVisible(false);
		TREE.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);	
		TREE.addTreeSelectionListener(new OptionsTreeSelectionListener(TREE));
        //TREE.setCellRenderer(new LimeTreeCellRenderer()); 
                 
		TREE.setModel(FILTERED_TREE_MODEL);
 
		SCROLL_PANE = new JScrollPane(TREE);
		SCROLL_PANE.setPreferredSize(new Dimension(150, 2000));
		SCROLL_PANE.setMinimumSize(new Dimension(150, 300));
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getLastSelectedPathComponent, scrollPathToVisible, setSelectionPath, startEditingAtPath
    /** 
     * Handles the button action 
     */ 
    public void actionPerformed(ActionEvent event) {
        if (event.getSource().equals(m_addButton)) {
            DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent();
 
            if (selNode != null) {
                // add new node as a child of a selected node at the end 
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New Node");
                m_model.insertNodeInto(newNode, selNode, selNode.getChildCount());
 
                // make the node visible by scroll to it 
                TreeNode[] nodes = m_model.getPathToRoot(newNode);
                TreePath path = new TreePath(nodes);
                m_tree.scrollPathToVisible(path);
 
                // select the newly added node 
                m_tree.setSelectionPath(path);
 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getModel, makeVisible, scrollPathToVisible, setSelectionPath
        testSelected(); 
    } 
 
    public void revealFailure(Test failure) {
        JTree tree = treeBrowser.getTree();
        TestTreeModel model = (TestTreeModel) tree.getModel();
        Vector<Test> vpath = new Vector<Test>();
        int index = model.findTest(failure, (Test) model.getRoot(), vpath);
        if (index >= 0 && vpath.size() != 0) {
            Object[] path = new Object[vpath.size() + 1];
            vpath.copyInto(path);
            Object last = path[vpath.size() - 1];
            path[vpath.size()] = model.getChild(last, index);
            TreePath selectionPath = new TreePath(path);
            tree.setSelectionPath(selectionPath);
            tree.makeVisible(selectionPath);
            tree.scrollPathToVisible(selectionPath);
        } 
    } 
 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add, setCellRenderer, setDragEnabled
		else 
			goToMappedTable.setEnabled(true);
		// setting mapped column menu enabled/disabled 
		if (typeOfSelectedEntity.equals(OntEntityTypes.OWL_THING_CLASS) 
				|| typeOfSelectedEntity.equals(OntEntityTypes.TABLE_CLASS))
			goToMappedColumn.setEnabled(false);
		else 
			goToMappedColumn.setEnabled(true);
	} 
} 
 
@SuppressWarnings("serial") 
class OntClassTreeCellRenderer extends DefaultTreeCellRenderer {
    private Icon clsIcon;
    private Icon equivlntClsIcon;
 
    OntClassTreeCellRenderer(Icon clsIcon, Icon equivlntClsIcon) {
        this.clsIcon = clsIcon;
        this.equivlntClsIcon = equivlntClsIcon;
    } 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getWidth, repaint, getRowBounds, getSelectionRows
     * component. 
     * 
     * @param tree the {@code JTree} to repaint the selection of. 
     */ 
    public static void repaintSelection(JTree tree) {
        int[] selectedRows = tree.getSelectionRows();
 
        // if there is a selected row, then repaint it. 
        if (selectedRows != null && selectedRows.length > 0) {
            // grab the bounds of the first and last selected cells in column 
            // one (index zero). 
            Rectangle firstSelectedCell = tree.getRowBounds(selectedRows[0]);
            Rectangle lastSelectedCell =
                    tree.getRowBounds(selectedRows[selectedRows.length - 1]);
 
            // create the rectangle to repaint by unioning the first and last 
            // selected cells in column one and then extending that rectangle 
            // to extend from the left edge of the table all the way to the 
            // right edge. 
            Rectangle repaintRectangle = firstSelectedCell.union(lastSelectedCell);

6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 JTree Methods: