Java Code Examples for javax.swing.JTree#setSelectionRow()
The following examples show how to use
javax.swing.JTree#setSelectionRow() .
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: Utils.java From netbeans with Apache License 2.0 | 6 votes |
static void previousRow(JTree tree) { int rowCount = tree.getRowCount(); if (rowCount > 0) { int selectedRow = tree.getSelectionModel().getMinSelectionRow(); if (selectedRow == -1) { selectedRow = (rowCount -1); } else { selectedRow--; if (selectedRow < 0) { selectedRow = (rowCount -1); } } tree.setSelectionRow(selectedRow); scrollTreeToSelectedRow(tree); } }
Example 2
Source File: ConstructorPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void initTree() { JTree tree = new JTree(getRootNode()); tree.setCellRenderer(new CheckBoxTreeRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.putClientProperty("JTree.lineStyle", "Angled"); //NOI18N NodeSelectionListener listener = new NodeSelectionListener(tree); tree.addMouseListener(listener); tree.addKeyListener(listener); tree.expandRow(0); tree.setShowsRootHandles(true); tree.setSelectionRow(0); initTree(tree); scrollPane.add(tree); scrollPane.setViewportView(tree); }
Example 3
Source File: ClassHierarchyPanel.java From netbeans with Apache License 2.0 | 6 votes |
public ClassHierarchyPanel(boolean isView) { initComponents(); if (!isView) { toolBar.remove(0); toolBar.remove(0); subtypeButton.setFocusable(true); supertypeButton.setFocusable(true); } setName(NbBundle.getMessage(getClass(), "CTL_ClassHierarchyTopComponent")); // NOI18N setToolTipText(NbBundle.getMessage(getClass(), "HINT_ClassHierarchyTopComponent")); // NOI18N tree = new JTree(); treeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); tree.setModel(treeModel); tree.setToggleClickCount(0); tree.setCellRenderer(new TreeRenderer()); tree.putClientProperty("JTree.lineStyle", "Angled"); //NOI18N tree.expandRow(0); tree.setShowsRootHandles(true); tree.setSelectionRow(0); tree.setRootVisible(false); hierarchyPane.add(tree); hierarchyPane.setViewportView(tree); tree.addMouseListener(mouseListener); }
Example 4
Source File: CheckNodeListener.java From netbeans with Apache License 2.0 | 5 votes |
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) { int[] rows = tree.getSelectionRows(); int newRow = rows == null || rows.length == 0 ? 0 : rows[0]; int maxcount = tree.getRowCount(); CheckNode node; do { if (next) { newRow++; if (newRow >= maxcount) { newRow = 0; } } else { newRow--; if (newRow < 0) { newRow = maxcount - 1; } } TreePath path = tree.getPathForRow(newRow); node = (CheckNode) path.getLastPathComponent(); if (!node.isLeaf()) { tree.expandRow(newRow); maxcount = tree.getRowCount(); } } while (!node.isLeaf()); tree.setSelectionRow(newRow); tree.scrollRowToVisible(newRow); }
Example 5
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
static void firstRow(JTree tree) { int rowCount = tree.getRowCount(); if (rowCount > 0) { tree.setSelectionRow(0); scrollTreeToSelectedRow(tree); } }
Example 6
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
static void nextRow(JTree tree) { int rowCount = tree.getRowCount(); if (rowCount > 0) { int selectedRow = tree.getSelectionModel().getMinSelectionRow(); if (selectedRow == -1) { selectedRow = 0; tree.setSelectionRow(selectedRow); } else { selectedRow++; } tree.setSelectionRow(selectedRow % rowCount); scrollTreeToSelectedRow(tree); } }
Example 7
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
static void lastRow(JTree tree) { int rowCount = tree.getRowCount(); if (rowCount > 0) { tree.setSelectionRow(rowCount - 1); scrollTreeToSelectedRow(tree); } }
Example 8
Source File: CheckNodeListener.java From netbeans with Apache License 2.0 | 5 votes |
static void selectNextPrev(final boolean next, boolean isQuery, JTree tree) { int[] rows = tree.getSelectionRows(); int newRow = rows == null || rows.length == 0 ? 0 : rows[0]; int maxcount = tree.getRowCount(); CheckNode node; do { if (next) { newRow++; if (newRow >= maxcount) { newRow = 0; } } else { newRow--; if (newRow < 0) { newRow = maxcount - 1; } } TreePath path = tree.getPathForRow(newRow); node = (CheckNode) path.getLastPathComponent(); if (!node.isLeaf()) { tree.expandRow(newRow); maxcount = tree.getRowCount(); } } while (!node.isLeaf()); tree.setSelectionRow(newRow); tree.scrollRowToVisible(newRow); if (isQuery) { CheckNodeListener.findInSource(node); } else { CheckNodeListener.openDiff(node); } }
Example 9
Source File: ImageTreePanel.java From moa with GNU General Public License v3.0 | 5 votes |
/** * Constructor. * @param chart */ public ImageTreePanel(ImageChart chart[]) { super(new GridLayout(1, 0)); this.chart = chart; //Create the nodes. DefaultMutableTreeNode top = new DefaultMutableTreeNode("Images"); imgPanel = new JPanel(); imgPanel.setLayout(new GridLayout(1, 0)); createNodes(top); tree = new JTree(top); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); tree.setSelectionRow(1); tree.addTreeSelectionListener(this); ImageIcon leafIcon = new ImageIcon("icon/img.png"); if (leafIcon != null) { DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setLeafIcon(leafIcon); tree.setCellRenderer(renderer); } imgPanel.updateUI(); JScrollPane treeView = new JScrollPane(tree); treeView.setMinimumSize(new Dimension(100, 50)); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setTopComponent(treeView); splitPane.setBottomComponent(imgPanel); splitPane.setDividerLocation(100); splitPane.setPreferredSize(new Dimension(500, 300)); add(splitPane); }