本文整理了Java中javax.swing.JTree.getSelectionCount()
方法的一些代码示例,展示了JTree.getSelectionCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getSelectionCount()
方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getSelectionCount
暂无
代码示例来源:origin: UISpec4J/UISpec4J
public void check() {
AssertAdapter.assertEquals(0, jTree.getSelectionCount());
}
};
代码示例来源:origin: org.orbisgis/toc
/**
* Enable the buttons to move the layers from the list of layers.
*/
private void enableDisableButtons() {
if (treeOption != null) {
btnCurrentRight.setEnabled(treeOption.getSelectionCount() > 0);
int selectedListIndex = lstSelection.getSelectedIndex();
btnCurrentLeft.setEnabled(selectedListIndex != -1);
}
}
代码示例来源:origin: nu.zoom/eon2
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
int row = tree.getRowForLocation(e.getX(), e.getY());
if (tree.getSelectionCount() < 2) {
tree.setSelectionRow(row);
}
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
代码示例来源:origin: com.l2fprod.common/l2fprod-common-directorychooser
public void valueChanged(TreeSelectionEvent e) {
getApproveSelectionAction().setEnabled(tree.getSelectionCount() > 0);
setSelectedFiles();
// the current directory is the one currently selected
TreePath currentDirectoryPath = tree.getSelectionPath();
if (currentDirectoryPath != null) {
File currentDirectory = ((FileTreeNode)currentDirectoryPath
.getLastPathComponent()).getFile();
chooser.setCurrentDirectory(currentDirectory);
}
}
}
代码示例来源:origin: joel-costigliola/assertj-swing
@Override
protected Pair<Boolean, Point> executeInEDT() {
boolean isSelected = (!singleSelectionRequired || tree.getSelectionCount() == 1) && tree.isPathSelected(path);
return Pair.of(isSelected, scrollToTreePath(tree, path, location));
}
});
代码示例来源:origin: org.owasp.jbrofuzz/jbrofuzz
final void closeFrame() {
JBroFuzz.PREFS.putInt("UI.H.mainSplitPanel", mainSplitPanel.getDividerLocation());
JBroFuzz.PREFS.putInt("UI.H.rHSplitPanel", rHSplitPanel.getDividerLocation());
JBroFuzz.PREFS.putInt("UI.H.rVSplitPanel", rVSplitPanel.getDividerLocation());
JBroFuzz.PREFS.putInt("UI.H.HeaderSelection", tree.getSelectionCount());
JBroFuzz.PREFS.putInt("UI.H.Height", HeaderFrame.this.getSize().height);
JBroFuzz.PREFS.putInt("UI.H.Width", HeaderFrame.this.getSize().width);
HeaderFrame.this.dispose();
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
@Override
public boolean isEnabled()
{
if( _tree.getSelectionCount() > 0 )
{
Breakpoint bp = ((BreakpointTree)_tree.getSelectionPath().getLastPathComponent()).getBreakpoint();
return bp != null && !bp.isStatic();
}
return false;
}
}
代码示例来源:origin: abbot/abbot
public Rectangle call() {
int row = tree.getRowForLocation(where.x, where.y);
if (tree.getLeadSelectionRow() != row
|| tree.getSelectionCount() != 1) {
// NOTE: the row bounds *do not* include the expansion handle
return tree.getRowBounds(row);
}
else {
return null;
}
}
});
代码示例来源:origin: joel-costigliola/assertj-swing
@Override
protected Pair<Boolean, Point> executeInEDT() {
checkEnabledAndShowing(tree);
Point p = scrollToVisible(tree, row, location);
boolean selected = (!singleSelectRequired || tree.getSelectionCount() == 1) && tree.isRowSelected(row);
return Pair.of(selected, p);
}
});
代码示例来源:origin: joel-costigliola/assertj-swing
@RunsInEDT
static void checkNoSelection(final @Nonnull JTree tree, final @Nonnull Description errMsg) {
execute(() -> {
if (tree.getSelectionCount() == 0) {
return;
}
String format = "[%s] expected no selection but was:<%s>";
String message = String.format(format, errMsg.value(), format(tree.getSelectionPaths()));
fail(message);
});
}
代码示例来源:origin: triplea-game/triplea
private void previous() {
if (tree.getSelectionCount() == 0) {
tree.setSelectionInterval(0, 0);
return;
}
final TreePath path = tree.getSelectionPath();
final TreeNode selected = (TreeNode) path.getLastPathComponent();
@SuppressWarnings("unchecked")
final Enumeration<TreeNode> nodeEnum =
((DefaultMutableTreeNode) tree.getModel().getRoot()).depthFirstEnumeration();
TreeNode previous = null;
while (nodeEnum.hasMoreElements()) {
final TreeNode current = nodeEnum.nextElement();
if (current == selected) {
break;
} else if (current.getParent() instanceof Step) {
previous = current;
}
}
if (previous != null) {
navigateTo(previous);
}
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core
@Override
public void mousePressed(MouseEvent e) {
// Get the Main Frame.
MainFrame mainFrame = GuiPackage.getInstance().getMainFrame();
// Close any Main Menu that is open
mainFrame.closeMenu();
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (tree.getPathForLocation(e.getX(), e.getY()) != null) {
log.debug("mouse pressed, updating currentPath");
currentPath = tree.getPathForLocation(e.getX(), e.getY());
}
if (selRow != -1 && isRightClick(e)) {
if (tree.getSelectionCount() < 2) {
tree.setSelectionPath(currentPath);
}
log.debug("About to display pop-up");
displayPopUp(e);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Construct a cell editor.
* @param tree the tree
*/
public TreeViewCellEditor(JTree tree) {
//Use a dummy DefaultTreeCellEditor - we'll set up the correct
//icon when we fetch the editor component (see EOF). Not sure
//it's wildly vaulable to subclass DefaultTreeCellEditor here -
//we override most everything
super(tree, new DefaultTreeCellRenderer());
// deal with selection if already exists
if (tree.getSelectionCount() == 1) {
lastPath = tree.getSelectionPath();
}
addCellEditorListener(this);
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
/** Construct a cell editor.
* @param tree the tree
*/
public TreeViewCellEditor(JTree tree) {
//Use a dummy DefaultTreeCellEditor - we'll set up the correct
//icon when we fetch the editor component (see EOF). Not sure
//it's wildly vaulable to subclass DefaultTreeCellEditor here -
//we override most everything
super(tree, new DefaultTreeCellRenderer());
// deal with selection if already exists
if (tree.getSelectionCount() == 1) {
lastPath = tree.getSelectionPath();
}
addCellEditorListener(this);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Construct a cell editor.
* @param tree the tree
*/
public TreeViewCellEditor(JTree tree) {
//Use a dummy DefaultTreeCellEditor - we'll set up the correct
//icon when we fetch the editor component (see EOF). Not sure
//it's wildly vaulable to subclass DefaultTreeCellEditor here -
//we override most everything
super(tree, new DefaultTreeCellRenderer());
// deal with selection if already exists
if (tree.getSelectionCount() == 1) {
lastPath = tree.getSelectionPath();
}
addCellEditorListener(this);
}
代码示例来源:origin: org.orbisgis/toc
@Override
public void run(ProgressMonitor pm) {
List<TreePath> dropPaths = new ArrayList<TreePath>(draggedResources.size());
for (int i = 0; i < draggedResources.size(); i++) {
String sourceName = draggedResources.get(i).getId();
if (pm.isCancelled()) {
break;
} else {
pm.progressTo(100 * i / draggedResources.size());
try {
ILayer nl = mapContext.createLayer(sourceName);
dropNode.insertLayer(nl, dropIndex);
dropPaths.add(getPathFromNode(new TocTreeNodeLayer(nl)));
} catch (Exception e) {
throw new RuntimeException(I18N.tr("Cannot add the layer to the destination"), e);
}
}
}
treeModel.nodeChanged(new TocTreeNodeLayer(dropNode));
// Select the new layer(s) if there is no selection
if(tree.getSelectionCount()==0) {
tree.setSelectionPaths(dropPaths.toArray(new TreePath[dropPaths.size()]));
}
}
代码示例来源:origin: joel-costigliola/assertj-swing
/**
* Returns the {@code String} representation of the given {@code Component}, which should be a {@code JTree} (or
* subclass).
*
* @param c the given {@code Component}.
* @return the {@code String} representation of the given {@code JTree}.
*/
@Override
@Nonnull protected String doFormat(@Nonnull Component c) {
JTree tree = (JTree) c;
String format = "%s[name=%s, selectionCount=%d, selectionPaths=%s, selectionMode=%s, enabled=%b, visible=%b, showing=%b";
return String.format(format, getRealClassName(c), quote(tree.getName()), tree.getSelectionCount(),
Arrays.format(selectionPaths(tree)), selectionMode(tree), tree.isEnabled(), tree.isVisible(),
tree.isShowing());
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
public void treeNodesRemoved (TreeModelEvent e) {
// called to removed from JTree.expandedState
super.treeNodesRemoved (e);
// part of bugfix #37279, if DnD is active then is useless select a nearby node
if (ExplorerDnDManager.getDefault ().isDnDActive ()) {
return ;
}
if (storeSelectedPaths == null || storeSelectedPaths.size () == tree.getSelectionCount ()) {
// selection not changed => it's redundant to change selection
return ;
}
if (tree.getSelectionCount () == 0) {
TreePath path = findSiblingTreePath (e.getTreePath (), e.getChildIndices ());
// bugfix #39564, don't select again the same object
if (path == null || path.equals (e.getTreePath ())) {
return ;
} else if (path.getPathCount () > 0) {
tree.setSelectionPath (path);
}
}
}
}
代码示例来源:origin: MegaMek/mekhq
@Override
public void actionPerformed(ActionEvent action) {
String command = action.getActionCommand();
if (command.equalsIgnoreCase("CONFIG_BOT")) {
PrincessBehaviorDialog pbd = new PrincessBehaviorDialog(frame,
scenario.getBotForce(index).getBehaviorSettings(),
scenario.getBotForce(index).getName());
pbd.setVisible(true);
if (!pbd.dialogAborted) {
scenario.getBotForce(index).setBehaviorSettings(pbd.getBehaviorSettings());
scenario.getBotForce(index).setName(pbd.getBotName());
}
} else if (command.equalsIgnoreCase("EDIT_UNIT")) {
if (tree.getSelectionCount() > 0) {
// row 0 is root node
int i = tree.getSelectionRows()[0] - 1;
UnitEditorDialog med = new UnitEditorDialog(frame,
scenario.getBotForce(index).getEntityList().get(i));
med.setVisible(true);
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
@Override
public void treeNodesRemoved(TreeModelEvent e) {
// called to removed from JTree.expandedState
super.treeNodesRemoved(e);
boolean wasSelected = removedNodeWasSelected;
removedNodeWasSelected = false;
// part of bugfix #37279, if DnD is active then is useless select a nearby node
if (ExplorerDnDManager.getDefault().isDnDActive()) {
return;
}
if (wasSelected && tree.getSelectionCount() == 0) {
TreePath path = findSiblingTreePath(e.getTreePath(), e.getChildIndices());
// bugfix #39564, don't select again the same object
if ((path == null) || e.getChildIndices().length == 0) {
return;
} else if (path.getPathCount() > 0) {
tree.setSelectionPath(path);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!