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

The following examples show how to use javax.swing.JTree#setShowsRootHandles() . 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: JSONTree.java    From rest-client with Apache License 2.0 6 votes vote down vote up
/**
* 
* @Title      : JSONTree 
* @Description: Default constructor 
* @Param      :
 */
public JSONTree()
{
    super(new GridLayout(1, 0));

    rootNode = new CheckBoxTreeNode(RESTConst.JSON);
    treeModel = new DefaultTreeModel(rootNode);

    tree = new JTree(treeModel);
    tree.setCellRenderer(new CheckBoxTreeCellRenderer());
    tree.setEditable(false);
    tree.setToolTipText(RESTConst.EXCLUDE_NODE);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(ma);

    JScrollPane scrollPane = new JScrollPane(tree);
    this.add(scrollPane);
    this.initPopupMenu();
}
 
Example 2
Source File: RepositoryTreeDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void init( final boolean addNewButtonPanel ) {

    setModal( true );
    setTitle( Messages.getInstance().getString( "SolutionRepositoryTreeDialog.Title" ) );

    this.addNewButtonPanel = addNewButtonPanel;

    this.repositoryTreeModel = new RepositoryTreeModel();

    repositoryBrowser = new JTree( repositoryTreeModel );
    repositoryBrowser.setCellRenderer( new RepositoryTreeCellRenderer() );
    repositoryBrowser.addMouseListener( new DoubleClickHandler() );
    repositoryBrowser.setRootVisible( true );
    repositoryBrowser.setShowsRootHandles( true );
    repositoryBrowser.setToggleClickCount( 1 );

    super.init();
    setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
  }
 
Example 3
Source File: WmsAssistantPage2.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component createPageComponent() {
    JPanel panel = new JPanel(new BorderLayout(4, 4));
    panel.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel.add(new JLabel("Available layers:"), BorderLayout.NORTH);

    LayerSourcePageContext context = getContext();
    modelCRS = (CoordinateReferenceSystem) context.getLayerContext().getCoordinateReferenceSystem();

    WMSCapabilities wmsCapabilities = (WMSCapabilities) context.getPropertyValue(
            WmsLayerSource.PROPERTY_NAME_WMS_CAPABILITIES);
    layerTree = new JTree(new WmsTreeModel(wmsCapabilities.getLayer()));
    layerTree.setRootVisible(false);
    layerTree.setShowsRootHandles(true);
    layerTree.setExpandsSelectedPaths(true);
    layerTree.setCellRenderer(new MyDefaultTreeCellRenderer());
    layerTree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    layerTree.getSelectionModel().addTreeSelectionListener(new LayerTreeSelectionListener());
    panel.add(new JScrollPane(layerTree), BorderLayout.CENTER);
    infoLabel = new JLabel(" ");
    panel.add(infoLabel, BorderLayout.SOUTH);
    getContext().setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_LAYER, null);
    return panel;
}
 
Example 4
Source File: ProductLayerAssistantPage.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component createPageComponent() {
    ProductTreeModel model = createTreeModel();
    tree = new JTree(model);
    tree.setEditable(false);
    tree.setShowsRootHandles(true);
    tree.setRootVisible(false);
    tree.setCellRenderer(new ProductNodeTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.getSelectionModel().addTreeSelectionListener(new ProductNodeSelectionListener());

    List<CompatibleNodeList> nodeLists = model.compatibleNodeLists;
    for (CompatibleNodeList nodeList : nodeLists) {
        tree.expandPath(new TreePath(new Object[]{nodeLists, nodeList}));
    }

    JPanel panel = new JPanel(new BorderLayout(4, 4));
    panel.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel.add(new JLabel("Compatible bands and tie-point grids:"), BorderLayout.NORTH);
    panel.add(new JScrollPane(tree), BorderLayout.CENTER);
    return panel;
}
 
Example 5
Source File: ConstructorPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 6
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 7
Source File: HttpMessageSelectorPanel.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
public HttpMessageSelectorPanel() {
    panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateGaps(true);

    SiteNode root =
            new SiteNode(
                    null,
                    -1,
                    Constant.messages.getString(
                            "fuzz.httpfuzzer.select.message.dialogue.rootNode"));
    SiteNode mainTreeRoot = Model.getSingleton().getSession().getSiteTree().getRoot();
    copyTree(mainTreeRoot, root);
    messagesTreeModel = new DefaultTreeModel(root);

    messagesTree = new JTree(messagesTreeModel);
    messagesTree.setVisibleRowCount(10);
    messagesTree.setShowsRootHandles(true);
    messagesTree.setName("HttpMessageSelectorTree");
    messagesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    messagesTree.setCellRenderer(
            new SiteMapTreeCellRenderer(Collections.<SiteMapListener>emptyList()));
    messagesTree.expandRow(0);

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(messagesTree);

    layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(scrollPane));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(scrollPane));
}
 
Example 8
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 9
Source File: MakeLayoutPane.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
private JTree initTreeLayoutExplore()
{
	final JTree treeLayoutExplore = new JTree(AndroidEditor.instance().getLayoutTreeModel());
	treeLayoutExplore.setShowsRootHandles(true);
	treeLayoutExplore.addTreeSelectionListener(new TreeSelectionListener(){
		public void valueChanged(TreeSelectionEvent arg0){
			Widget w = (Widget) treeLayoutExplore.getLastSelectedPathComponent();
			AndroidEditor.instance().select(w);
		}
	});
	treeLayoutExplore.setBorder(BorderFactory.createTitledBorder("Layout Explorer"));
	treeLayoutExplore.setMinimumSize(new Dimension(200, 400));
	return treeLayoutExplore;
}
 
Example 10
Source File: EntityTreePanel.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
    * list all entities in the world.  Double click an item to get its panel.
    * See https://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html
    */
public void updateEntityTree() {
	// list all objects in scene
    DefaultMutableTreeNode newTop = createTreeNodes(ro);
	JTree newTree = new JTree(newTop);

    newTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    newTree.setShowsRootHandles(true);
    newTree.addTreeSelectionListener(this);
	//tree.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

	if(oldTree!=null) {
		// preserve the original expansions
		ArrayList<TreePath> expanded = new ArrayList<TreePath>();
		for(int i=0;i<oldTree.getRowCount();++i) {
			if(oldTree.isExpanded(i)) {
				expanded.add(oldTree.getPathForRow(i));
			}
		}
		// restore the expanded paths
		for(TreePath p : expanded) {
			newTree.expandPath(p);
		}
		// restore the selected paths
		TreePath[] paths = oldTree.getSelectionPaths();
		newTree.setSelectionPaths(paths);
	}
	
	if(!newTree.equals(oldTree)) {
		scroll.setViewportView(newTree);
		oldTree=newTree;
		oldTop =newTop;
	}
}
 
Example 11
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 12
Source File: DynamicTree.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public DynamicTree() {
    super(new GridLayout(1, 0));

    rootNode = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(new MyTreeModelListener());
    tree = new JTree(treeModel);
    tree.setEditable(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setShowsRootHandles(true);

    JScrollPane scrollPane = new JScrollPane(tree);
    add(scrollPane);
}
 
Example 13
Source File: MWPaneTitleTreeManager.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
/**
 * Create the title tree manager.
 * 
 * @param textPane Text pane.
 */
public MWPaneTitleTreeManager(MWPane textPane) {

  // Text pane
  this.textPane = textPane;
  splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  JScrollPane scrollContents = new JScrollPane(textPane);
  scrollContents.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  splitPane.setBottomComponent(scrollContents);

  // Table of contents
  JPanel panelTOC = new JPanel(new GridBagLayout());
  GridBagConstraints constraints = new GridBagConstraints();
  constraints.fill = GridBagConstraints.BOTH;
  constraints.gridheight = 1;
  constraints.gridwidth = 1;
  constraints.gridx = 0;
  constraints.gridy = 0;
  constraints.insets = new Insets(0, 0, 0, 0);
  constraints.ipadx = 0;
  constraints.ipady = 0;
  constraints.weightx = 1;
  constraints.weighty = 1;

  // Toolbar
  JToolBar toolbarButtons = new JToolBar(SwingConstants.VERTICAL);
  toolbarButtons.setFloatable(false);
  JButton buttonLess = Utilities.createJButton(
      "gnome-go-previous.png", EnumImageSize.NORMAL,
      GT._T("Decrement title level"), false, null);
  buttonLess.addActionListener(EventHandler.create(
      ActionListener.class, this, "decreaseLevel"));
  toolbarButtons.add(buttonLess);
  JButton buttonMore = Utilities.createJButton(
      "gnome-go-next.png", EnumImageSize.NORMAL,
      GT._T("Increment title level"), false, null);
  buttonMore.addActionListener(EventHandler.create(
      ActionListener.class, this, "increaseLevel"));
  toolbarButtons.add(buttonMore);
  JButton buttonDone = Utilities.createJButton(
      "commons-approve-icon.png", EnumImageSize.NORMAL,
      GT._T("Validate the new table of contents"), false, null);
  buttonDone.addActionListener(EventHandler.create(
      ActionListener.class, this, "validate"));
  toolbarButtons.add(buttonDone);
  constraints.weightx = 0;
  panelTOC.add(toolbarButtons, constraints);
  constraints.gridx++;

  // Tree node renderer
  DefaultTreeCellRenderer rendererToc = new DefaultTreeCellRenderer();
  rendererToc.setLeafIcon(rendererToc.getClosedIcon());

  // Table of contents Tree
  MWPaneTitleTreeNode rootToc = new MWPaneTitleTreeNode(null);
  modelToc = new DefaultTreeModel(rootToc);
  treeToc = new JTree(modelToc);
  treeToc.setRootVisible(false);
  treeToc.setShowsRootHandles(true);
  treeToc.getSelectionModel().setSelectionMode(
      TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
  treeToc.setCellRenderer(rendererToc);
  treeToc.addTreeSelectionListener(EventHandler.create(
      TreeSelectionListener.class, this, "selectionChanged"));
  JScrollPane scrollTree = new JScrollPane(treeToc);
  scrollTree.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  constraints.weightx = 1;
  panelTOC.add(scrollTree, constraints);
  constraints.gridx++;

  // Second tree
  MWPaneTitleTreeNode rootToc2 = new MWPaneTitleTreeNode(null);
  modelToc2 = new DefaultTreeModel(rootToc2);
  treeToc2 = new JTree(modelToc2);
  treeToc2.setRootVisible(false);
  treeToc2.setShowsRootHandles(true);
  treeToc2.setCellRenderer(rendererToc);
  JScrollPane scrollTree2 = new JScrollPane(treeToc2);
  scrollTree2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  constraints.weightx = 1;
  panelTOC.add(scrollTree2, constraints);
  constraints.gridx++;
  
  splitPane.setTopComponent(panelTOC);

  // Hide table of contents
  hideToc();
}
 
Example 14
Source File: OverviewInfoTreeUI.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Constructs new overview info tree.
 * 
 * @param inFrame The application frame in which this exists.
 */
public OverviewInfoTreeUI(ApplicationFrame inFrame) {
	// Create the top node.
	_topNode = new DefaultMutableTreeNode("EA Overview");
	_theFrame = inFrame;

	// Create a tree that allows one selection at a time.
	_infoTreeModel = new DefaultTreeModel(_topNode);
	_infoTree = new JTree(_infoTreeModel);

	_infoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	_infoTree.setRootVisible(false); // Hides root node
	_infoTree.setShowsRootHandles(true); // Shows nodes off root

	DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

	renderer.setOpenIcon(null);
	renderer.setClosedIcon(null);
	renderer.setLeafIcon(null);
	_infoTree.setCellRenderer(renderer);

	// Add tree into scroll pane and then to this pane
	this.setViewportView(_infoTree);
	this.setMinimumSize(new Dimension(150, 200));

	_popupMenu = new JPopupMenu();
	_newPosition = new Point(50, 50);

	buildPopupMenu();

	// Create Category Heads
	_tree_sketches = new DefaultMutableTreeNode("Sketches");

	_topNode.add(_tree_sketches);

	_tree_views = new DefaultMutableTreeNode("Views");

	_topNode.add(_tree_views);

	// Initialize ArrayList of expansion state information
	expanState = new ArrayList<>();
}
 
Example 15
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 16
Source File: BroadcastDialog.java    From SmartIM with Apache License 2.0 4 votes vote down vote up
protected void initTree(JTree tree) {
    tree.setCellRenderer(new CheckBoxTreeCellRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
}
 
Example 17
Source File: IMContactView.java    From SmartIM with Apache License 2.0 4 votes vote down vote up
protected void initTree(JTree tree) {
    tree.setCellRenderer(new ContactTreeCellRenderer());
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    tree.addMouseListener(new IMContactDoubleClicker(getImPanel()));
}
 
Example 18
Source File: ModelInfoTreeUI.java    From CQL with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Default constructor
 *
 * @param inFrame
 */
public ModelInfoTreeUI(F inFrame) {
	// Create the top node.
	_topNode = new DefaultMutableTreeNode("EA Sketch");
	_theFrame = inFrame;
	_newPosition = new Point(50, 50);

	// Create a tree that allows one selection at a time.
	_infoTreeModel = new DefaultTreeModel(_topNode);
	_infoTree = new JTree(_infoTreeModel);

	_infoTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	_infoTree.setRootVisible(false); // Hides root node
	_infoTree.setShowsRootHandles(true); // Shows nodes off root

	DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();

	renderer.setOpenIcon(null);
	renderer.setClosedIcon(null);
	renderer.setLeafIcon(null);
	_infoTree.setCellRenderer(renderer);

	// Add tree into scroll pane and then to this pane
	this.setViewportView(_infoTree);
	this.setMinimumSize(new Dimension(150, 200));

	_popupMenu = new JPopupMenu();

	buildPopupMenu();

	// Create Category Heads
	_tree_entities = new DefaultMutableTreeNode("Entities");

	_topNode.add(_tree_entities);

	_tree_constraints = new DefaultMutableTreeNode("Constraints");

	_topNode.add(_tree_constraints);

	_tree_constraints_commutative = new DefaultMutableTreeNode("Commutative Diagrams");

	_tree_constraints.add(_tree_constraints_commutative);

	_tree_constraints_product = new DefaultMutableTreeNode("Product Constraints");

	_tree_constraints.add(_tree_constraints_product);

	_tree_constraints_pullback = new DefaultMutableTreeNode("Pullback Constraints");

	_tree_constraints.add(_tree_constraints_pullback);

	_tree_constraints_equalizer = new DefaultMutableTreeNode("Equalizer Constraints");

	_tree_constraints.add(_tree_constraints_equalizer);

	_tree_constraints_sum = new DefaultMutableTreeNode("Sum Constraints");

	_tree_constraints.add(_tree_constraints_sum);

	_tree_constraints_limit = new DefaultMutableTreeNode("Limit Constraints");

	_tree_constraints.add(_tree_constraints_limit);

	// Initialize ArrayList of expansion state information
	expanState = new ArrayList<>();
}