Java Code Examples for javax.swing.JTree#setModel()

The following examples show how to use javax.swing.JTree#setModel() . 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: ClassHierarchyPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 2
Source File: ProjectDialog.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initComponents()
{
	setLayout(new BorderLayout());

	mainPanel = new JPanel();
	mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

	JScrollPane mainScrollPane = new JScrollPane();
	mainScrollPane.setPreferredSize(new Dimension(300, 400));
	add(mainScrollPane, BorderLayout.CENTER);

	projectTree = new JTree();
	projectTree.setEditable(true);
	projectTree.setModel(new ProjectTreeModel(xmlProjectType));
	projectTree.setCellRenderer(new ProjectTreeCellRenderer(frame));
	projectTree.setCellEditor(new ProjectTreeCellEditor(projectTree));
	projectTree.getSelectionModel().setSelectionMode(
			TreeSelectionModel.SINGLE_TREE_SELECTION);
	projectTree.addMouseListener(new ProjectTreeMouseListener(frame,
			projectTree));
	projectTree.expandRow(1);

	mainScrollPane.getViewport().add(projectTree);

	pack();
}
 
Example 3
Source File: DatasetTreeView.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
DatasetTreeView() {
  // the catalog tree
  tree = new JTree() {
    public JToolTip createToolTip() {
      return new MultilineTooltip();
    }
  };
  tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
  tree.setCellRenderer(new MyTreeCellRenderer());

  tree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      if (selRow != -1) {
        TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
        if (node instanceof VariableNode) {
          Variable v = ((VariableNode) node).var;
          firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
        }
      }
    }
  });

  tree.putClientProperty("JTree.lineStyle", "Angled");
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setToggleClickCount(1);
  ToolTipManager.sharedInstance().registerComponent(tree);

  // layout
  setLayout(new BorderLayout());
  add(new JScrollPane(tree), BorderLayout.CENTER);
}
 
Example 4
Source File: QQBroadcastDialog.java    From SmartIM with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTab(JTabbedPane host) {
    // recentTree = new JTree();
    friendTree = new JTree();
    groupTree = new JTree();
    discussTree = new JTree();

    // JScrollPane scrollPane1 = new JScrollPane(recentTree);
    // tabHost.addTab("最近", null, scrollPane1, null);

    JScrollPane scrollPane2 = new JScrollPane(friendTree);
    tabHost.addTab("好友", null, scrollPane2, null);

    JScrollPane scrollPane3 = new JScrollPane(groupTree);
    tabHost.addTab("群组", null, scrollPane3, null);

    JScrollPane scrollPane4 = new JScrollPane(discussTree);
    tabHost.addTab("讨论组", null, scrollPane4, null);

    initTrees(recentTree, friendTree, groupTree, discussTree);
    // root1 = new QQContactTreeNode(false, "recent", imPanel);
    root2 = new QQContactTreeNode(false, "friend", imPanel);
    root3 = new QQContactTreeNode(false, "group", imPanel);
    root4 = new QQContactTreeNode(false, "discuss", imPanel);
    root2.update();
    root3.update();
    root4.update();

    // recentModel = new ContactTreeMode(root1);
    friendModel = new ContactTreeMode(root2);
    groupModel = new ContactTreeMode(root3);
    discussModel = new ContactTreeMode(root4);

    // recentTree.setModel(recentModel);
    friendTree.setModel(friendModel);
    groupTree.setModel(groupModel);
    discussTree.setModel(discussModel);

}
 
Example 5
Source File: WXBroadcastDialog.java    From SmartIM with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTab(JTabbedPane host) {
    // recentTree = new JTree();
    friendTree = new JTree();
    groupTree = new JTree();
    discussTree = new JTree();

    // JScrollPane scrollPane1 = new JScrollPane(recentTree);
    // tabHost.addTab("最近", null, scrollPane1, null);

    JScrollPane scrollPane2 = new JScrollPane(friendTree);
    tabHost.addTab("好友", null, scrollPane2, null);

    JScrollPane scrollPane3 = new JScrollPane(groupTree);
    tabHost.addTab("群组", null, scrollPane3, null);

    JScrollPane scrollPane4 = new JScrollPane(discussTree);
    tabHost.addTab("讨论组", null, scrollPane4, null);

    initTrees(recentTree, friendTree, groupTree, discussTree);
    // root1 = new WXContactTreeNode(false, "recent", imPanel);
    root2 = new WXContactTreeNode(false, "friend", imPanel);
    root3 = new WXContactTreeNode(false, "group", imPanel);
    root4 = new WXContactTreeNode(false, "discuss", imPanel);
    root2.update();
    root3.update();
    root4.update();

    // recentModel = new ContactTreeMode(root1);
    friendModel = new ContactTreeMode(root2);
    groupModel = new ContactTreeMode(root3);
    discussModel = new ContactTreeMode(root4);

    // recentTree.setModel(recentModel);
    friendTree.setModel(friendModel);
    groupTree.setModel(groupModel);
    discussTree.setModel(discussModel);

}
 
Example 6
Source File: ObjectSelector.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
public ObjectSelector() {
	super( "Object Selector" );
	setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	addWindowListener(FrameBox.getCloseListener("ShowObjectSelector"));
	addWindowFocusListener(new MyFocusListener());

	top = new DefaultMutableTreeNode();
	treeModel = new DefaultTreeModel(top);
	tree = new JTree();
	tree.setModel(treeModel);
	tree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
	tree.setRootVisible(false);
	tree.setShowsRootHandles(true);
	tree.setInvokesStopCellEditing(true);

	treeView = new JScrollPane(tree);
	getContentPane().add(treeView);

	entSequence = 0;

	addComponentListener(FrameBox.getSizePosAdapter(this, "ObjectSelectorSize", "ObjectSelectorPos"));

	tree.addTreeSelectionListener( new MyTreeSelectionListener() );
	treeModel.addTreeModelListener( new MyTreeModelListener(tree) );

	tree.addMouseListener(new MyMouseListener());
	tree.addKeyListener(new MyKeyListener());
}
 
Example 7
Source File: VisualProfiler.java    From diirt with MIT License 5 votes vote down vote up
private void initComponents(){
    treeRoot            = new DefaultMutableTreeNode(new File(ProfileGraph2D.LOG_FILEPATH));
    treeModel           = new DefaultTreeModel(treeRoot);
    tree                = new JTree(treeRoot){
        @Override
        public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus){
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            try{
                File f = (File) node.getUserObject();
                return f.getName();
            }
            catch(Exception e){
                return node.toString();
            }
        }
    };
    tree                .setModel(treeModel);
    tree                .expandRow(0);
    tree                .setShowsRootHandles(true);

    btnOpenFiles        = new JButton("Open File(s)");
    actionButtons       .add(btnOpenFiles);
    btnDeleteFiles      = new JButton("Delete File(s)");
    actionButtons       .add(btnDeleteFiles);
    btnReloadFiles      = new JButton("Refresh");
    actionButtons       .add(btnReloadFiles);
}
 
Example 8
Source File: TreeUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void createTree(JTree jTree1, String[] leaves) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("", true);
    jTree1.setModel(new DefaultTreeModel(root));
    jTree1.setRootVisible(false);
    DefaultMutableTreeNode currentNode = root;
    Map<String, DefaultMutableTreeNode> pathList = new HashMap<String, DefaultMutableTreeNode>();
    for (int i = 0; i < leaves.length; i++) {

        String[] s = leaves[i].split("/");
        for (int j = 0; j < s.length; j++) {

            DefaultMutableTreeNode node = new DefaultMutableTreeNode(s[j], j != s.length - 1);
            String path = getPath(currentNode.getUserObjectPath()) + getPath(node.getUserObjectPath());
            DefaultMutableTreeNode pathNode = pathList.get(path);

            if (pathNode == null) {
                pathList.put(path, node);
                currentNode.add(node);
            } else {
                node = pathNode;
            }

            currentNode = node;
        }
        currentNode = root;
    }
}
 
Example 9
Source File: LogParserView.java    From yGuard with MIT License 4 votes vote down vote up
static void setParser( final JTree tree, final YGuardLogParser parser ) {
  tree.setModel(parser.getTreeModel());
  tree.putClientProperty("PARSER", parser);
}
 
Example 10
Source File: WindowsDirectoryChooserUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void installComponents(JFileChooser chooser) {
  this.chooser = (JDirectoryChooser)chooser;

  chooser.setLayout(LookAndFeelTweaks.createBorderLayout());
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

  Component accessory = chooser.getAccessory();
  if (accessory != null) {
    chooser.add("North", chooser.getAccessory());
  }

  tree = new JTree() {
    public String getToolTipText(MouseEvent event) {
      String tip = WindowsDirectoryChooserUI.this.getToolTipText(event);
      if (tip == null) {
        return super.getToolTipText(event);
      } else {
        return tip;
      }
    }
  };
  tree.addTreeExpansionListener(new TreeExpansion());

  tree.setModel(new FileSystemTreeModel(chooser.getFileSystemView()));
  tree.setRootVisible(false);
  tree.setShowsRootHandles(false);
  tree.setCellRenderer(new FileSystemTreeRenderer());
  tree.setToolTipText("");

  chooser.add("Center", treeScroll = new JScrollPane(tree));
  treeScroll.setPreferredSize(new Dimension(300, 300));

  approveButton = new JButton();
  approveButton.setAction(getApproveSelectionAction());

  cancelButton = new JButton();
  cancelButton.addActionListener(getCancelSelectionAction());

  buttonPanel = new JPanel(LookAndFeelTweaks.createButtonAreaLayout());
  buttonPanel.add(approveButton);
  buttonPanel.add(cancelButton);
  chooser.add("South", buttonPanel);

  updateView(chooser);
}
 
Example 11
Source File: TabPanelOrganization.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;		

		UnitManager unitManager = Simulation.instance().getUnitManager();
		LocalUnitManagerListener unitManagerListener = new LocalUnitManagerListener();
		unitManager.addUnitManagerListener(unitManagerListener);

		// Create label panel.
		JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		topContentPanel.add(titlePanel);

		// Prepare label
		JLabel tlabel = new JLabel(Msg.getString("TabPanelStructure.title"), JLabel.CENTER); //$NON-NLS-1$
		tlabel.setFont(new Font("Serif", Font.BOLD, 16));
		// tlabel.setForeground(new Color(102, 51, 0)); // dark brown
		titlePanel.add(tlabel);

		// Prepare info panel.
		infoPanel = new JPanel(new GridLayout(1, 2, 0, 0));
//		infoPanel.setBorder(new MarsPanelBorder());
		centerContentPanel.add(infoPanel, BorderLayout.NORTH);

		// Create label panel.
		JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		infoPanel.add(labelPanel);

		// Prepare label
		JLabel label = new JLabel(Msg.getString("TabPanelStructure.label"), JLabel.CENTER); //$NON-NLS-1$
		labelPanel.add(label);

		root = new DefaultMutableTreeNode(settlement.getName());

		tree = new JTree(root);
		tree.setVisibleRowCount(8);
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		//Listen for when the selection changes.
//	    tree.addTreeSelectionListener(new MyTreeModelListener());
	    
		// Use treeSearchable
		TreeSearchable searchable = SearchableUtils.installSearchable(tree);
		searchable.setPopupTimeout(5000);
		searchable.setCaseSensitive(false);
		
		defaultTreeModel = new DefaultTreeModel(root);
		tree.setModel(defaultTreeModel);

		centerContentPanel.add(new JScrollPane(tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
				ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
	
		buildTreeNodes();
		
		initNodes();
	}
 
Example 12
Source File: RssGUI.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public RssGUI() {
	

	model = new MagicNewsTableModel();
	table = new JXTable(model);
	tree = new JTree();
	JSplitPane splitNews = new JSplitPane();
	editorPane = MTGUIBrowserComponent.createBrowser();
	JSplitPane splitTreeTable = new JSplitPane();
	JPanel leftPanel = new JPanel();
	rootNode = new DefaultMutableTreeNode(MTGControler.getInstance().getLangService().getCapitalize("RSS_MODULE"));
	JPanel panelControl = new JPanel();
	btnNewButton = UITools.createBindableJButton(null,MTGConstants.ICON_NEW,KeyEvent.VK_N,"new news entry");
	btnSave = UITools.createBindableJButton(null,MTGConstants.ICON_SAVE,KeyEvent.VK_S,"save news entry");
	btnDelete =UITools.createBindableJButton(null,MTGConstants.ICON_DELETE,KeyEvent.VK_D,"delete news entry");
	lblLoading = AbstractBuzyIndicatorComponent.createLabelComponent();
	newsPanel = new NewsEditorPanel();
	
	setLayout(new BorderLayout(0, 0));
	tree.setPreferredSize(new Dimension(150, 64));
	splitNews.setOrientation(JSplitPane.VERTICAL_SPLIT);
	leftPanel.setLayout(new BorderLayout(0, 0));
	tree.setModel(new DefaultTreeModel(rootNode));
	tree.setCellRenderer(new NewsTreeCellRenderer());

	
	splitNews.setLeftComponent(new JScrollPane(table));
	splitNews.setRightComponent(new JScrollPane(editorPane));
	add(splitTreeTable, BorderLayout.CENTER);
	splitTreeTable.setRightComponent(splitNews);
	splitTreeTable.setLeftComponent(leftPanel);
	leftPanel.add(new JScrollPane(tree), BorderLayout.CENTER);
	
	leftPanel.add(panelControl, BorderLayout.NORTH);
	panelControl.add(btnNewButton);
	panelControl.add(btnSave);
	panelControl.add(btnDelete);
	panelControl.add(lblLoading);
	leftPanel.add(newsPanel, BorderLayout.SOUTH);
			

	initTree();

	initActions();


}
 
Example 13
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static void refreshTree(JTree tree, TreeModel model) {
    List<List<String>> expandedNodes = getExpandedNodes(tree);
    tree.setModel(model);
    expandTreeNodes(tree, expandedNodes);
}
 
Example 14
Source File: OptionsFilter.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**Install a filtering model to the given tree, using given model as the source
 * of the data.
 *
 * @param tree to which the model should be installed
 * @param source source {@link TreeModel} - the data to show will be gathered from this model
 * @param acceptor acceptor specifying whether the given original tree node should or should not
 *                 be visible for given user's filter
 * @param delegatingTreeModelListeners is allowing to delegate tree model listeners to tree 
 */
public void installFilteringModel(JTree tree, TreeModel source, Acceptor acceptor, boolean delegatingTreeModelListeners) {
    if (!SwingUtilities.isEventDispatchThread()) {
        throw new IllegalStateException("Not in AWT Event Dispatch Thread");
    }
    
    usedCallback.run();
    tree.setModel(new FilteringTreeModel(source, doc, acceptor, delegatingTreeModelListeners));
}