javax.swing.JTable#setComponentPopupMenu ( )源码实例Demo

下面列出了javax.swing.JTable#setComponentPopupMenu ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected void addPopupMenu( final JTable table )
{
	final JPopupMenu popupMenu = new JPopupMenu();
	final JMenuItem deleteItem = new JMenuItem( "Delete" );

	deleteItem.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed( final ActionEvent e )
		{
			delete();
			System.out.println( "Right-click performed on table and choose DELETE" );
		}
	});

	popupMenu.add( deleteItem );

	table.setComponentPopupMenu( popupMenu );
}
 
public static void initTMTable(JTable table) {
    InputMap imTD = table.getInputMap(WHEN_FOCUSED);
    ActionMap amTD = table.getActionMap();
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mItemEnc = new JMenuItem("Encrypt");
    popup.add(mItemEnc);
    Action enc = getEncryptAction(table);
    mItemEnc.setAccelerator(Keystroke.ENCRYPT);
    mItemEnc.addActionListener(enc);
    imTD.put(Keystroke.ENCRYPT, "encrypt");
    amTD.put("encrypt", enc);
    table.setComponentPopupMenu(popup);
    JtableUtils.addlisteners(table, Boolean.FALSE);
}
 
源代码3 项目: mzmine2   文件: TaskProgressTable.java
/**
 * Constructor
 */
public TaskProgressTable() {

  super(new BorderLayout());

  add(new JLabel("Tasks in progress..."), BorderLayout.NORTH);

  TaskControllerImpl taskController = (TaskControllerImpl) MZmineCore.getTaskController();

  taskTable = new JTable(taskController.getTaskQueue());
  taskTable.setCellSelectionEnabled(false);
  taskTable.setColumnSelectionAllowed(false);
  taskTable.setRowSelectionAllowed(true);
  taskTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  taskTable.setDefaultRenderer(JComponent.class, new ComponentCellRenderer());
  taskTable.getTableHeader().setReorderingAllowed(false);

  JScrollPane jJobScroll = new JScrollPane(taskTable);
  add(jJobScroll, BorderLayout.CENTER);

  // Create popup menu and items
  popupMenu = new JPopupMenu();

  priorityMenu = new JMenu("Set priority...");
  highPriorityMenuItem = GUIUtils.addMenuItem(priorityMenu, "High", this);
  normalPriorityMenuItem = GUIUtils.addMenuItem(priorityMenu, "Normal", this);
  popupMenu.add(priorityMenu);

  cancelTaskMenuItem = GUIUtils.addMenuItem(popupMenu, "Cancel task", this);
  cancelAllMenuItem = GUIUtils.addMenuItem(popupMenu, "Cancel all tasks", this);

  // Addd popup menu to the task table
  taskTable.setComponentPopupMenu(popupMenu);

  // Set the width for first column (task description)
  taskTable.getColumnModel().getColumn(0).setPreferredWidth(350);

  jJobScroll.setPreferredSize(new Dimension(600, 120));

}
 
protected void addPopupMenu( final JTable table )
{
	final JPopupMenu popupMenu = new JPopupMenu();

	for ( final ViewExplorerSetable item : staticPopups )
		popupMenu.add( item.setViewExplorer( this ) );

	table.setComponentPopupMenu( popupMenu );
}
 
 方法所在类
 同类方法