當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeSelectionModel類代碼示例

本文整理匯總了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();
}
 
開發者ID:guilhebl,項目名稱:routerapp,代碼行數:26,代碼來源:NavigationView.java

示例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);
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:21,代碼來源:OntologyBrowser.java

示例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") );
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CheckTreeView.java

示例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);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:17,代碼來源:OperatorTree.java

示例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);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:25,代碼來源:PlotConfigurationTree.java

示例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());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:RTreeTest.java

示例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());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:RTreeTest.java

示例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());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:RTreeTest.java

示例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());
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:24,代碼來源:RTreeTest.java

示例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;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:26,代碼來源:ViewResultsFullVisualizer.java

示例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());
		}
	});
}
 
開發者ID:AlloyTools,項目名稱:org.alloytools.alloy,代碼行數:26,代碼來源:OurTree.java

示例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);
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:30,代碼來源:CheckboxTree.java

示例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);
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:19,代碼來源:StateTree.java

示例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);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:WizardTree.java

示例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);

    }
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:27,代碼來源:RelationTreePanel.java


注:本文中的javax.swing.tree.TreeSelectionModel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。