Java Code Examples for javax.swing.JTree#addMouseListener()
The following examples show how to use
javax.swing.JTree#addMouseListener() .
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: ProjectDialog.java From quickfix-messenger with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 2
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 6 votes |
void connect( JTree errorTree, DefaultTreeModel errModel, JComboBox severityComboBox, JCheckBox tasklistCheckBox, JPanel customizerPanel, JEditorPane descriptionTextArea) { this.errorTree = errorTree; this.errModel = errModel; this.severityComboBox = severityComboBox; this.tasklistCheckBox = tasklistCheckBox; this.customizerPanel = customizerPanel; this.descriptionTextArea = descriptionTextArea; valueChanged( null ); errorTree.addKeyListener(this); errorTree.addMouseListener(this); errorTree.getSelectionModel().addTreeSelectionListener(this); severityComboBox.addActionListener(this); tasklistCheckBox.addChangeListener(this); }
Example 3
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 6 votes |
void connect( JTree errorTree, JComboBox severityComboBox, JCheckBox tasklistCheckBox, JPanel customizerPanel, JEditorPane descriptionTextArea) { this.errorTree = errorTree; this.severityComboBox = severityComboBox; this.tasklistCheckBox = tasklistCheckBox; this.customizerPanel = customizerPanel; this.descriptionTextArea = descriptionTextArea; valueChanged( null ); errorTree.addKeyListener(this); errorTree.addMouseListener(this); errorTree.getSelectionModel().addTreeSelectionListener(this); severityComboBox.addActionListener(this); tasklistCheckBox.addChangeListener(this); }
Example 4
Source File: ConstructorPanel.java From netbeans with Apache License 2.0 | 6 votes |
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 5
Source File: BlocksTreeViewManager.java From openAGV with Apache License 2.0 | 5 votes |
/** * Registers a listener for mouse events that helps to select the element in the tree view that * the user has clicked on. * This is necessary as long as {@link AbstractTreeViewPanel#selectItem(java.lang.Object)} simply * selects the first occurrence of the given object, not expecting the object to occur in the tree * more than once. */ private void initSpecializedSelector() { JTree tree = getTreeView().getTree(); tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { tree.setSelectionPath(tree.getClosestPathForLocation(e.getX(), e.getY())); } }); }
Example 6
Source File: ObjectSelector.java From jaamsim with Apache License 2.0 | 5 votes |
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: ExtendedCheckTreeMouseSelectionManager.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public ExtendedCheckTreeMouseSelectionManager(JTree tree, boolean selectAll) { this.tree = tree; selectionModel = new ExtendedCheckTreeSelectionModel(tree.getModel()); if (selectAll) { selectionModel.addSelectionPath(tree.getPathForRow(0)); } tree.setCellRenderer(new ExtendedCheckTreeCellRenderer(new DefaultTreeCellRenderer(), selectionModel)); tree.addMouseListener(this); selectionModel.addTreeSelectionListener(this); }
Example 8
Source File: CheckTree.java From Spark with Apache License 2.0 | 5 votes |
/** * Constructs a new CheckBox tree. * * @param rootNode Node that is the root of this tree. */ public CheckTree(CheckNode rootNode) { tree = new JTree(rootNode); tree.setCellRenderer(new CheckRenderer()); tree.setRowHeight(18); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setToggleClickCount(1000); tree.putClientProperty("JTree.lineStyle", "Angled"); tree.addMouseListener(new NodeSelectionListener(tree)); setLayout(new BorderLayout()); add(tree, BorderLayout.CENTER); }
Example 9
Source File: ModelsPanel.java From ramus with GNU General Public License v3.0 | 5 votes |
private void init() { treeModel.setRoot(createRoot()); tree = new JTree(treeModel) { @Override public TreeCellRenderer getCellRenderer() { TreeCellRenderer renderer = super.getCellRenderer(); if (renderer == null) return null; ((DefaultTreeCellRenderer) renderer).setLeafIcon(new ImageIcon( getClass().getResource("/images/function.png"))); return renderer; } }; tree.setCellRenderer(new Renderer()); tree.setEditable(true); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) { openDiagram(); } } }); tree.setRootVisible(true); JScrollPane pane = new JScrollPane(); pane.setViewportView(tree); this.add(pane, BorderLayout.CENTER); }
Example 10
Source File: ManagementModel.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private JTree makeTree(ManagementModelNode root) { root.explore(); JTree tree = new CommandBuilderTree(cliGuiCtx, new DefaultTreeModel(root)); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeExpansionListener(new ManagementTreeExpansionListener((DefaultTreeModel) tree.getModel())); tree.addTreeSelectionListener(new ManagementTreeSelectionListener()); tree.addMouseListener(new ManagementTreeMouseListener(tree)); return tree; }
Example 11
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
void connect( final JTree errorTree, DefaultTreeModel errorTreeModel, JLabel severityLabel, JComboBox severityComboBox, JCheckBox tasklistCheckBox, JPanel customizerPanel, JEditorPane descriptionTextArea, final JComboBox configCombo, JButton editScript, HintsSettings settings, boolean direct) { this.errorTree = errorTree; this.errorTreeModel = errorTreeModel; this.severityLabel = severityLabel; this.severityComboBox = severityComboBox; this.tasklistCheckBox = tasklistCheckBox; this.customizerPanel = customizerPanel; this.descriptionTextArea = descriptionTextArea; this.configCombo = configCombo; this.editScript = editScript; this.direct = direct; if (configCombo.getSelectedItem() !=null) { originalSettings = ((Configuration) configCombo.getSelectedItem()).getSettings(); } else if (settings != null) { originalSettings = settings; } else { originalSettings = HintsSettings.getGlobalSettings(); } writableSettings = new WritableSettings(originalSettings, direct); valueChanged( null ); errorTree.addKeyListener(this); errorTree.addMouseListener(this); errorTree.getSelectionModel().addTreeSelectionListener(this); this.configCombo.addItemListener(this); severityComboBox.addActionListener(this); tasklistCheckBox.addChangeListener(this); }
Example 12
Source File: CheckTreeManager.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
public CheckTreeManager(JTree tree) { this.tree = tree; selectionModel = new CheckTreeSelectionModel(tree.getModel()); tree.setCellRenderer(new CheckTreeCellRenderer(tree.getCellRenderer(), selectionModel)); tree.addMouseListener(this); //鼠标监听 selectionModel.addTreeSelectionListener(this); //树选择监听 }
Example 13
Source File: DatasetTreeView.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 14
Source File: BroadcastDialog.java From SmartIM with Apache License 2.0 | 4 votes |
protected void initTree(JTree tree) { tree.setCellRenderer(new CheckBoxTreeCellRenderer()); tree.setShowsRootHandles(false); tree.setRootVisible(false); tree.addMouseListener(new CheckBoxTreeNodeSelectionListener()); }
Example 15
Source File: CorefEditor.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * This method intiates the GUI for co-reference editor */ @Override protected void initGUI() { //get a pointer to the textual view used for highlights Iterator<DocumentView> centralViewsIter = owner.getCentralViews().iterator(); while (textView == null && centralViewsIter.hasNext()) { DocumentView aView = centralViewsIter.next(); if (aView instanceof TextualDocumentView) textView = (TextualDocumentView) aView; } textPane = (JTextArea) ( (JScrollPane) textView.getGUI()).getViewport(). getView(); highlighter = textPane.getHighlighter(); chainToolTipAction = new ChainToolTipAction(); chainToolTipTimer = new javax.swing.Timer(500, chainToolTipAction); chainToolTipTimer.setRepeats(false); newCorefAction = new NewCorefAction(); newCorefActionTimer = new javax.swing.Timer(500, newCorefAction); newCorefActionTimer.setRepeats(false); colorGenerator = new ColorGenerator(); // main Panel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); // topPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); // subPanel subPanel = new JPanel(); subPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // showAnnotations Button showAnnotations = new JToggleButton("Show"); showAnnotations.addActionListener(this); // annotSets annotSets = new JComboBox<String>(); annotSets.addActionListener(this); // get all the annotationSets Map<String,AnnotationSet> annotSetsMap = document.getNamedAnnotationSets(); annotSetsModel = new DefaultComboBoxModel<String>(); if (annotSetsMap != null) { String [] array = annotSetsMap.keySet().toArray(new String[annotSetsMap.keySet().size()]); for(int i=0;i<array.length;i++) { annotSetsMap.get(array[i]).addAnnotationSetListener(this); } annotSetsModel = new DefaultComboBoxModel<String>(array); } document.getAnnotations().addAnnotationSetListener(this); annotSetsModel.insertElementAt(DEFAULT_ANNOTSET_NAME, 0); annotSets.setModel(annotSetsModel); // annotTypes annotTypesModel = new DefaultComboBoxModel<String>(); annotTypes = new JComboBox<String>(annotTypesModel); annotTypes.addActionListener(this); subPanel.add(new JLabel("Sets : ")); subPanel.add(annotSets); JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); tempPanel.add(new JLabel("Types : ")); tempPanel.add(annotTypes); tempPanel.add(showAnnotations); // intialises the Data initData(); // and creating the tree corefTree = new JTree(rootNode); corefTree.putClientProperty("JTree.lineStyle", "None"); corefTree.setRowHeight(corefTree.getRowHeight() * 2); corefTree.setLargeModel(true); corefTree.setAutoscrolls(true); //corefTree.setRootVisible(false); //corefTree.setShowsRootHandles(false); corefTree.addMouseListener(new CorefTreeMouseListener()); corefTree.setCellRenderer(new CorefTreeCellRenderer()); mainPanel.add(topPanel, BorderLayout.NORTH); mainPanel.add(new JScrollPane(corefTree), BorderLayout.CENTER); topPanel.add(subPanel, BorderLayout.CENTER); topPanel.add(tempPanel, BorderLayout.SOUTH); // get the highlighter textPaneMouseListener = new TextPaneMouseListener(); annotSets.setSelectedIndex(0); // finally show the tree //annotSetSelectionChanged(); document.addDocumentListener(this); document.getFeatures().addFeatureMapListener(this); }
Example 16
Source File: IMContactView.java From SmartIM with Apache License 2.0 | 4 votes |
protected void initTree(JTree tree) { tree.setCellRenderer(new ContactTreeCellRenderer()); tree.setShowsRootHandles(false); tree.setRootVisible(false); tree.addMouseListener(new IMContactDoubleClicker(getImPanel())); }
Example 17
Source File: DatabaseManagerSwing.java From evosql with Apache License 2.0 | 4 votes |
private void initGUI() { JPanel pCommand = new JPanel(); pResult = new JPanel(); nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand, pResult); // Added: (weconsultants@users) nsSplitPane.setOneTouchExpandable(true); pCommand.setLayout(new BorderLayout()); pResult.setLayout(new BorderLayout()); Font fFont = new Font("Dialog", Font.PLAIN, 12); txtCommand = new JTextArea(7, 40); txtCommand.setMargin(new Insets(5, 5, 5, 5)); txtCommand.addKeyListener(this); txtCommandScroll = new JScrollPane(txtCommand); txtResult = new JTextArea(25, 40); txtResult.setMargin(new Insets(5, 5, 5, 5)); txtResultScroll = new JScrollPane(txtResult); txtCommand.setFont(fFont); txtResult.setFont(new Font("Courier", Font.PLAIN, 12)); pCommand.add(txtCommandScroll, BorderLayout.CENTER); gResult = new GridSwing(); TableSorter sorter = new TableSorter(gResult); tableModel = sorter; gResultTable = new JTable(sorter); sorter.setTableHeader(gResultTable.getTableHeader()); gScrollPane = new JScrollPane(gResultTable); gResultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gResult.setJTable(gResultTable); //getContentPane().setLayout(new BorderLayout()); pResult.add(gScrollPane, BorderLayout.CENTER); // Set up the tree rootNode = new DefaultMutableTreeNode("Connection"); treeModel = new DefaultTreeModel(rootNode); tTree = new JTree(treeModel); tScrollPane = new JScrollPane(tTree); // System.out.println("Adding mouse listener"); tTree.addMouseListener(this); tScrollPane.setPreferredSize(new Dimension(200, 400)); tScrollPane.setMinimumSize(new Dimension(70, 100)); txtCommandScroll.setPreferredSize(new Dimension(560, 100)); txtCommandScroll.setMinimumSize(new Dimension(180, 100)); gScrollPane.setPreferredSize(new Dimension(460, 300)); ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tScrollPane, nsSplitPane); // Added: (weconsultants@users) ewSplitPane.setOneTouchExpandable(true); fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER); // Added: (weconsultants@users) jStatusLine = new JLabel(); iReadyStatus = new JButton(new ImageIcon(CommonSwing.getIcon("StatusReady"))); iReadyStatus.setSelectedIcon( new ImageIcon(CommonSwing.getIcon("StatusRunning"))); pStatus = new JPanel(); pStatus.setLayout(new BorderLayout()); pStatus.add(iReadyStatus, BorderLayout.WEST); pStatus.add(jStatusLine, BorderLayout.CENTER); fMain.getContentPane().add(pStatus, "South"); doLayout(); if (fMain instanceof java.awt.Window) { ((java.awt.Window) fMain).pack(); } else { ((Container) fMain).validate(); } }
Example 18
Source File: EditorRootPane.java From libGDX-Path-Editor with Apache License 2.0 | 4 votes |
private void createNoProjectTree() { projectTree = new JTree(); createNoProjectTreeRoot(); projectTree.addMouseListener(mouseListener); projectTreeScroll = new JScrollPane(projectTree); }
Example 19
Source File: TreePanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
public TreePanel(NMONVisualizerGui gui) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(ROOT_NAME); tree = new JTree(root); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(new TreeCellRenderer()); setViewportView(tree); // make sure panel takes up entire parent, but the actual tree is offset slightly setBorder(null); tree.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)); // data changes modify the tree gui.addDataSetListener(this); tree.addMouseListener(new TreeMouseListener(gui, tree)); tree.setDragEnabled(true); tree.setTransferHandler(new TreeTransferHandler(gui)); tree.setCellRenderer(new TreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(tree); }
Example 20
Source File: ScreenInfoPanel.java From hprof-tools with MIT License | 4 votes |
public ScreenInfoPanel(@Nonnull final TabbedInfoWindow mainWindow, @Nonnull List<Screen> screens) { super(new BorderLayout()); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Inspect View"); item.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainWindow.showInstancesListTab(rightClickedViewed.getClassName(), Collections.singletonList(rightClickedViewed.getInstance())); } }); popupMenu.add(item); imagePanel = new ImagePanel(); viewTree = new JTree(new DefaultMutableTreeNode("Loading...")); viewTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); viewTree.addTreeSelectionListener(this); viewTree.addMouseListener(new PopupListener(popupMenu)); JScrollPane treeScroller = new JScrollPane(viewTree); rootPicker = new JComboBox(new Vector<Object>(screens)); rootPicker.addItemListener(this); JPanel settingsPanel = new JPanel(new GridLayout(1, 2)); showBoundsBox = new JCheckBox("Show layout bounds", true); showBoundsBox.addItemListener(this); forceAlpha = new JCheckBox("Force alpha", true); forceAlpha.addItemListener(this); settingsPanel.add(showBoundsBox); settingsPanel.add(forceAlpha); settingsPanel.setBorder(new EmptyBorder(10, 0, 0, 0)); infoTable = new JTable(); infoTable.setRowSelectionAllowed(false); infoTable.setColumnSelectionAllowed(false); infoTable.setCellSelectionEnabled(false); infoTable.setShowGrid(true); JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); bottomPanel.add(infoTable, BorderLayout.CENTER); bottomPanel.add(infoTable.getTableHeader(), BorderLayout.NORTH); bottomPanel.add(settingsPanel, BorderLayout.SOUTH); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(rootPicker, BorderLayout.NORTH); leftPanel.add(treeScroller, BorderLayout.CENTER); leftPanel.add(bottomPanel, BorderLayout.SOUTH); // Split pane for the tree and image views JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(leftPanel); splitPane.setRightComponent(imagePanel); add(splitPane, BorderLayout.CENTER); selectedScreen = screens.get(0); update(); }