javax.swing.JTree.setComponentPopupMenu()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中javax.swing.JTree.setComponentPopupMenu()方法的一些代码示例,展示了JTree.setComponentPopupMenu()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.setComponentPopupMenu()方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:setComponentPopupMenu

JTree.setComponentPopupMenu介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  JFrame frame = new JFrame();
  final JTree tree = new JTree();

  JPopupMenu menu = new JPopupMenu();
  menu.add(new JMenuItem("Test"));
  tree.setComponentPopupMenu(menu);
  frame.add(tree);

  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}

代码示例来源:origin: aterai/java-swing-tips

private MainPanel() {
 super(new BorderLayout());
 JTree tree = new JTree();
 tree.setComponentPopupMenu(new TreePopupMenu());
 add(new JScrollPane(tree));
 setPreferredSize(new Dimension(320, 240));
}

代码示例来源:origin: stackoverflow.com

JPopupMenu popup = new JPopupMenu();
 final Action action = new AbstractAction("empty") {
   @Override
   public void actionPerformed(ActionEvent e) {
     // TODO Auto-generated method stub
   }
 };
 popup.add(action); 
 JTree tree = new JTree() {
   /** 
    * @inherited <p>
    */
   @Override
   public Point getPopupLocation(MouseEvent e) {
     if (e != null) {
       TreePath path = getClosestPathForLocation(e.getX(), e.getY());
       action.putValue(Action.NAME, String.valueOf(path.getLastPathComponent()));
       return e.getPoint();
     }
     action.putValue(Action.NAME, "no mouse"); 
     return null;
   }
 };
 tree.setComponentPopupMenu(popup);

代码示例来源:origin: aterai/java-swing-tips

private MainPanel() {
 super(new GridLayout(1, 2));
 JTree t = new JTree(makeDefaultTreeModel());
 t.setComponentPopupMenu(new TreePopupMenu());
 add(makeTitledPanel("Default", new JScrollPane(t)));
 DefaultTreeModel model = makeDefaultTreeModel();
 JTree tree = new JTree(model);
 tree.setComponentPopupMenu(new TreePopupMenu());
 // model.setAsksAllowsChildren(true);
 JCheckBox check = new JCheckBox("setAsksAllowsChildren");
 check.addActionListener(e -> {
  model.setAsksAllowsChildren(((JCheckBox) e.getSource()).isSelected());
  tree.repaint();
 });
 JPanel p = new JPanel(new BorderLayout());
 p.add(new JScrollPane(tree));
 p.add(check, BorderLayout.SOUTH);
 add(makeTitledPanel("setAsksAllowsChildren", p));
 setPreferredSize(new Dimension(320, 240));
}

代码示例来源:origin: org.scijava/scijava-ui-swing

private void initTreeView() {
  treeModel = new DefaultTreeModel(rootNode);
  tree = new JTree(treeModel);
  tree.setRootVisible(false);
  DefaultTreeCellRenderer cellRenderer = new DefaultTreeCellRenderer();
  cellRenderer.setIcon(null);
  cellRenderer.setLeafIcon(null);
  cellRenderer.setOpenIcon(null);
  tree.setCellRenderer(cellRenderer);
  tree.setComponentPopupMenu(menu);
  tree.setEditable(false);
  tree.setShowsRootHandles(true);
  tree.addTreeSelectionListener(this::selectionChanged);
}

代码示例来源:origin: org.zaproxy/zap

treeSite.setComponentPopupMenu(new SitesCustomPopupMenu());

代码示例来源:origin: stackoverflow.com

t = new JTree(model);
t.setEditable(true);
t.setComponentPopupMenu(getPopUpMenu());
t.addMouseListener(getMouseListener());
setDefaultCloseOperation(EXIT_ON_CLOSE);

代码示例来源:origin: org.zaproxy/zap

treeContext.setComponentPopupMenu(new ContextsCustomPopupMenu());

代码示例来源:origin: org.zaproxy/zap

treeAlert.setShowsRootHandles(true);
treeAlert.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
treeAlert.setComponentPopupMenu(new JPopupMenu() {

代码示例来源:origin: sensepost/yeti

trDomainTree.setComponentPopupMenu(pmNetworkActions);
trDomainTree.setName("trDomainTree"); // NOI18N
trDomainTree.addMouseListener(new java.awt.event.MouseAdapter() {

相关文章

JTree类方法