本文整理汇总了Java中javax.swing.tree.TreeSelectionModel类的典型用法代码示例。如果您正苦于以下问题:Java TreeSelectionModel类的具体用法?Java TreeSelectionModel怎么用?Java TreeSelectionModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeSelectionModel类属于javax.swing.tree包,在下文中一共展示了TreeSelectionModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/**
*
*/
private void buildTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("user");
tree = new JTree(root);
tree.putClientProperty("JTree.lineStyle", "Angled");
tree.setCellRenderer(new NavigationTreeCellRenderer());
tree.setShowsRootHandles(true);
DefaultTreeSelectionModel model = new DefaultTreeSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
graphsCategory = new DefaultMutableTreeNode("graphs");
mouseAdapter = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
itemSelected(e);
}
};
tree.addMouseListener(mouseAdapter);
root.add(graphsCategory);
loadGraphs();
}
示例2: OntologyBrowser
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public OntologyBrowser(OWLOntology ontology, Set<String> rootsToRemove) {
super();
this.ontology = ontology;
this.rootConcept = "Thing";
this.buildTreeModel();
for (String concept : rootsToRemove) {
DefaultMutableTreeNode node = getNodeFromName(concept);
this.dtm.removeNodeFromParent(node);
}
this.setModel(this.dtm);
// set the tree selection model
DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
dtsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.setSelectionModel(dtsm);
// set the tree renderer
OntologyRenderer myRenderer = new OntologyRenderer();
this.setCellRenderer(myRenderer);
this.setRootVisible(false);
}
示例3: CheckTreeView
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
setFocusable( false );
CheckListener l = new CheckListener();
tree.addMouseListener( l );
tree.addKeyListener( l );
CheckRenderer check = new CheckRenderer();
tree.setCellRenderer( check );
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(false);
InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
if( null != input )
input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
setBorder( UIManager.getBorder("ScrollPane.border") );
}
示例4: OperatorTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/** Creates a new operator tree. */
public OperatorTree(MainFrame mainFrame) {
super();
this.mainFrame = mainFrame;
setCellRenderer(new OperatorTreeCellRenderer());
addTreeSelectionListener(this);
addTreeExpansionListener(this);
addMouseListener(this);
// forces the tree to ask the nodes for the correct row heights
// must also be invoked after LaF changes...
setRowHeight(0);
getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
}
示例5: PlotConfigurationTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public PlotConfigurationTree(PlotConfiguration plotConfiguration, DataTable dataTable,
DataTableColumnListTransferHandler aTH) {
super();
expandAll();
// forces the tree to ask the nodes for the correct row heights
// must also be invoked after LaF changes...
setRowHeight(0);
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
setExpandsSelectedPaths(true);
// DnD support
setDragEnabled(true);
setDropMode(DropMode.INSERT);
// Rendering
setShowsRootHandles(false);
setBackground(Colors.WHITE);
setCellRenderer(new PlotConfigurationTreeCellRenderer(aTH));
putClientProperty("JTree.lineStyle", "Horizontal");
createNewTreeModel(plotConfiguration);
}
示例6: noNodesSelected
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public void noNodesSelected() throws Throwable, InvocationTargetException {
final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
siw(new Runnable() {
@Override public void run() {
tree.expandRow(0);
}
});
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
RTree rTree = new RTree(tree, null, null, lr);
rTree.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("[]", call.getState());
}
示例7: singleNodeSelected
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public void singleNodeSelected() throws Throwable, InvocationTargetException {
final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
siw(new Runnable() {
@Override public void run() {
tree.expandRow(0);
tree.setSelectionRow(0);
}
});
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
RTree rTree = new RTree(tree, null, null, lr);
rTree.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("[/Root Node]", call.getState());
}
示例8: multpleNodesSelected
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public void multpleNodesSelected() throws Throwable, InvocationTargetException {
final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
siw(new Runnable() {
@Override public void run() {
tree.expandRow(0);
tree.setSelectionRows(new int[] { 0, 2 });
}
});
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
RTree rTree = new RTree(tree, null, null, lr);
rTree.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("[/Root Node, /Root Node/Parent 2]", call.getState());
}
示例9: singleNodeWithSpecialChars
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public void singleNodeWithSpecialChars() throws Throwable, InvocationTargetException {
final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
siw(new Runnable() {
@Override public void run() {
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
root.setUserObject("Root Node [] , / Special");
tree.expandRow(0);
tree.setSelectionRow(0);
}
});
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
RTree rTree = new RTree(tree, null, null, lr);
rTree.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("[/Root Node [] \\, \\\\/ Special]", call.getState());
}
示例10: createLeftPanel
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
private synchronized Component createLeftPanel() {
SampleResult rootSampleResult = new SampleResult();
rootSampleResult.setSampleLabel("Root");
rootSampleResult.setSuccessful(true);
root = new SearchableTreeNode(rootSampleResult, null);
treeModel = new DefaultTreeModel(root);
jTree = new JTree(treeModel);
jTree.setCellRenderer(new ResultsNodeRenderer());
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
jTree.setRootVisible(false);
jTree.setShowsRootHandles(true);
JScrollPane treePane = new JScrollPane(jTree);
treePane.setPreferredSize(new Dimension(200, 300));
VerticalPanel leftPane = new VerticalPanel();
leftPane.add(treePane, BorderLayout.CENTER);
leftPane.add(createComboRender(), BorderLayout.NORTH);
autoScrollCB = new JCheckBox(JMeterUtils.getResString("view_results_autoscroll")); // $NON-NLS-1$
autoScrollCB.setSelected(false);
autoScrollCB.addItemListener(this);
leftPane.add(autoScrollCB, BorderLayout.SOUTH);
return leftPane;
}
示例11: OurTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
Font font = OurUtil.getVizFont().deriveFont((float) fontSize);
OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
renderer.setFont(font);
renderer.invalidate();
renderer.validate();
setRowHeight(0); // To allow variable row height on Mac OS X
setCellRenderer(renderer);
setFont(font);
setBorder(new EmptyBorder(8, 8, 2, 2));
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
putClientProperty("JTree.lineStyle", "Angled");
setRootVisible(true);
setForeground(Color.BLACK);
setBackground(Color.WHITE);
setOpaque(true);
addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = OurTree.this.getSelectionPath();
if (path != null)
OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
}
});
}
示例12: CheckboxTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/**
* Constructs a tree, with cell renderer and editor set by
* {@link #createRenderer()} and {@link #createEditor()}.
*/
public CheckboxTree() {
setCellRenderer(createRenderer());
setCellEditor(createEditor());
setEditable(true);
setRootVisible(false);
setShowsRootHandles(true);
// make sure the checkbox never selects the label
// note that the BasicTreeUI may not be what is used in the current LAF,
// but I don't know any other way to modify the selection behaviour
BasicTreeUI ui = new BasicTreeUI() {
@Override
protected void selectPathForEvent(TreePath path, MouseEvent event) {
if (!isOverCheckBox(path, event.getPoint().x)) {
super.selectPathForEvent(path, event);
}
}
};
setUI(ui);
// initialise the tree model
this.topNode = new DefaultMutableTreeNode();
this.treeModel = new DefaultTreeModel(this.topNode);
setModel(this.treeModel);
// set selection mode
getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
}
示例13: StateTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
/**
* Creates a new state list.
*/
public StateTree(Simulator simulator) {
this.simulator = simulator;
setEnabled(false);
setLargeModel(true);
setRootVisible(false);
setShowsRootHandles(true);
setEnabled(false);
setToggleClickCount(0);
setModel(getModel());
getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
this.setCellRenderer(new DisplayTreeCellRenderer(this));
installListeners();
ToolTipManager.sharedInstance()
.registerComponent(this);
}
示例14: MyTree
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
public MyTree(int wizardType, WizardModel model)
{
super(model);
// Some basic properties
setEditable(true);
setShowsRootHandles(true);
setRootVisible(wizardType == WizardHelper.WIZARD_TYPE_CONTRIBUTION);
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// Set the renderer and editor
CellRenderer renderer = new CellRenderer(repository);
CellEditor editor = new CellEditor(repository, this, renderer);
setCellRenderer(renderer);
setCellEditor(editor);
}
示例15: init
import javax.swing.tree.TreeSelectionModel; //导入依赖的package包/类
private void init() {
setLayout(new BorderLayout());
tree = new WebTree(root);
tree.setToggleClickCount(2);
tree.setScrollsOnExpand(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setRootVisible(true);
tree.addTreeSelectionListener(this);
WebScrollPane treeScrollWrapper = new WebScrollPane(tree);
WebPanel wrapper = new WebPanel(treeScrollWrapper);
wrapper.setMargin(5, 10, 10, 0);
MButtonPanel buttonPanel = new MButtonPanel(moveUpButton, moveDownButton,
addButton, addSubRelationButton, removeButton)
.withVerticalLayout()
.withAllButtonsEnabled(true)
.withMargin(10);
add(wrapper, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.EAST);
}