当前位置: 首页>>代码示例>>Java>>正文


Java JTable.addMouseListener方法代码示例

本文整理汇总了Java中javax.swing.JTable.addMouseListener方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.addMouseListener方法的具体用法?Java JTable.addMouseListener怎么用?Java JTable.addMouseListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTable的用法示例。


在下文中一共展示了JTable.addMouseListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ButtonCellRenderer

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Create the ButtonCellRenderer to be used as a renderer and editor. The
 * renderer and editor will automatically be installed on the TableColumn of
 * the specified column.
 *
 * @param table the table containing the button renderer/editor
 * @param action the Action to be invoked when the button is invoked
 * @param column the column to which the button renderer/editor is added
 */
public ButtonCellRenderer(JTable table, Action action, int column) {
    this.table = table;
    this.action = action;

    renderButton = new JButton();
    editButton = new JButton();
    editButton.setFocusPainted(false);
    editButton.addActionListener(this);
    originalBorder = editButton.getBorder();
    setFocusBorder(new LineBorder(Color.BLUE));

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.getColumn(column).setCellRenderer(this);
    columnModel.getColumn(column).setCellEditor(this);
    table.addMouseListener(this);
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:26,代码来源:ButtonCellRenderer.java

示例2: CourseListPanel

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * Create the panel.
 */
public CourseListPanel(String user,ProfessorFrame pf) throws Exception{
	setLayout(new BorderLayout(0, 0));
       TableCellRenderer buttonRenderer = new ButtonRenderer();
	dao = new ProfessorDAO();
	model=new tableModelTeach(dao.getAllCourses(user),user,pf);
	table = new JTable();
	table.setRowHeight(30);
	
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.setDefaultRenderer(JButton.class,buttonRenderer);
	table.addMouseListener(new JTableButtonMouseListener(table));
	table.setModel(model);
	JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	//resizeColumnWidth(table);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	TableColumnModel tcm = table.getColumnModel();
	tcm.getColumn(0).setPreferredWidth(800);    
	tcm.getColumn(1).setPreferredWidth(200);    
	
	scrollPane.setBounds(10, 57, 1320, 450);
	add(scrollPane, BorderLayout.CENTER);
}
 
开发者ID:jtatia,项目名称:Course-Management-System,代码行数:26,代码来源:CourseListPanel.java

示例3: buildTablePanel

import javax.swing.JTable; //导入方法依赖的package包/类
private JScrollPane buildTablePanel() {
      table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
      TableColumn nameColumn = new TableColumn(0);
      TableColumn addressColumn = new TableColumn(1);
      table.addColumn(nameColumn);
      table.addColumn(addressColumn);
      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
      table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
      table.addMouseListener(new AddressMouseListener());
      
      // TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);
      
      JScrollPane scrollPane = new JScrollPane(table);
      return scrollPane;
  }
 
开发者ID:ZencashOfficial,项目名称:zencash-swing-wallet-ui,代码行数:19,代码来源:AddressBookPanel.java

示例4: SimpleTableDemo

import javax.swing.JTable; //导入方法依赖的package包/类
public SimpleTableDemo() {
    super(new GridLayout(1, 0));

    String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

    Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
            { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
            { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
            { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
            { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };

    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    if (DEBUG) {
        table.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                printDebugData(table);
            }
        });
    }

    // Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    // Add the scroll pane to this panel.
    add(scrollPane);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:30,代码来源:SimpleTableDemo.java

示例5: buildTablePanel

import javax.swing.JTable; //导入方法依赖的package包/类
private JScrollPane buildTablePanel() {
    table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
    TableColumn nameColumn = new TableColumn(0);
    TableColumn addressColumn = new TableColumn(1);
    table.addColumn(nameColumn);
    table.addColumn(addressColumn);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
    table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
    table.addMouseListener(new AddressMouseListener());
    JScrollPane scrollPane = new JScrollPane(table);
    return scrollPane;
}
 
开发者ID:ca333,项目名称:komodoGUI,代码行数:13,代码来源:AddressBookPanel.java

示例6: jbInit

import javax.swing.JTable; //导入方法依赖的package包/类
void jbInit() throws Exception {
  setBorder(BorderList.etchedBorder5);
  ActionListener actionEventHandler = new ActionEventHandler();
  MouseListener mouseEventHandler = new MouseEventHandler();

  addButton = new JButton("Add");
  addButton.setActionCommand("Add");
  addButton.addActionListener(actionEventHandler);

  removeButton = new JButton("Remove");
  removeButton.setActionCommand("Remove");
  removeButton.addActionListener(actionEventHandler);

  //by lila
  JPanel p1 = new JPanel();
  p1.setLayout(new FlowLayout(FlowLayout.CENTER));
  p1.add(addButton);
  p1.add(removeButton);

  model = new MyFieldTableModel();
  fieldTable = new JTable(model);

  fieldTable.setRowSelectionAllowed(true);
  fieldTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  fieldTable.addMouseListener(mouseEventHandler);
  fieldTable.setBorder(BorderList.bebelBorder);

  scrollpane = new JScrollPane(fieldTable);
  scrollpane.setPreferredSize(new Dimension(550,220));

  //by lila
  JPanel p2 = new JPanel();
  p2.setLayout(new BorderLayout(0,5));
  TitledBorder border = new TitledBorder(new EtchedBorder(),"Field Table");
  border.setTitleFont(FontList.regularFont);
  border.setTitleColor(Color.black);
  p2.setBorder(border);
  p2.add(p1,BorderLayout.SOUTH);
  p2.add(scrollpane,BorderLayout.CENTER);
  p2.add(new JPanel(),BorderLayout.EAST);
  p2.add(new JPanel(),BorderLayout.WEST);

  setLayout(new FlowLayout(FlowLayout.CENTER));
  add(p2);
}
 
开发者ID:FJplant,项目名称:AntIDE,代码行数:46,代码来源:FieldPanel.java

示例7: setupTableListeners

import javax.swing.JTable; //导入方法依赖的package包/类
public void setupTableListeners(JTable table) {
	TableCheckBoxMouseListener tableCheckBoxMouseListener = new TableCheckBoxMouseListener(table);
	table.addMouseListener(tableCheckBoxMouseListener);

	table.getSelectionModel().addListSelectionListener(new RowListener(table));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:7,代码来源:VariationPerParameterTableController.java

示例8: PanelCourses

import javax.swing.JTable; //导入方法依赖的package包/类
public PanelCourses(Student student,CourseOutline courseoutline) throws Exception{
	this.co=courseoutline;
	setLayout(new BorderLayout(0, 0));
	cmdao=new CourseMappingDAO();
	/*JScrollPane scrollPane = new JScrollPane();
	add(scrollPane, BorderLayout.CENTER);*/
	
	JLabel lblCoursesTaken = new JLabel("Courses Taken");
	//scrollPane.setColumnHeaderView(lblCoursesTaken);
	
	StudentCourseOutlineDAO sctodao = new StudentCourseOutlineDAO(student);
	ArrayList<String> course = sctodao.Coursedata(student);
      /* DefaultListModel<String> model = new DefaultListModel<>();
	int size = course.size();
	for(int i=0; i<size; i++){
    	model.addElement(course.get(i));
	}
	JList list = new JList(model);
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.addListSelectionListener(new ListSelectionListener() {
		public void valueChanged(ListSelectionEvent arg0) {
			String course_name=(String)list.getSelectedValue();
			//System.out.println("Course id is::"+course_name);
			//System.out.println("Batch is ::"+student.getBatch());
			String path=cmdao.getDirectoryPath(course_name, student.getBatch());
			
			//System.out.println("Path is::"+path);
			//System.out.println(path);
			co.c_panel.curr_subject=course_name;
			try {
				co.c_panel.resetPanes(student, path);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 jb=(JLabel)co.panel.getComponent(7);
			 jb_c=(JLabel)co.panel.getComponent(6);
			jb.setVisible(true);
			jb_c.setVisible(true);
			jb.setText(course_name);
			CardLayout card=(CardLayout)co.panel_1.getLayout();
			co.panel_2.getComponent(0).setEnabled(true);
			card.show(co.panel_1, "CoursePanel");
		}
	});
	scrollPane.setViewportView(list);*/
	
	TableCellRenderer buttonRenderer = new ButtonRenderer();
	model=new CourseTableModel(course,this,student);
	table = new JTable();
	table.setRowHeight(30);
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.setDefaultRenderer(JButton.class,buttonRenderer);
	table.addMouseListener(new JTableButtonMouseListener(table));
	table.setModel(model);
	JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	//resizeColumnWidth(table);
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	TableColumnModel tcm = table.getColumnModel();
	tcm.getColumn(0).setPreferredWidth(800);    
	tcm.getColumn(1).setPreferredWidth(200);    
	
	
	scrollPane.setBounds(10, 57, 1320, 450);
	scrollPane.setColumnHeaderView(lblCoursesTaken);
	add(scrollPane, BorderLayout.CENTER);
	
	
}
 
开发者ID:jtatia,项目名称:Course-Management-System,代码行数:70,代码来源:PanelCourses.java

示例9: SimpleTableDemo

import javax.swing.JTable; //导入方法依赖的package包/类
public SimpleTableDemo(LazyReplicatedMap<String,StringBuilder> map) {
    super();
    this.map = map;

    this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    //final JTable table = new JTable(data, columnNames);
    table = new JTable(dataModel);

    table.setPreferredScrollableViewportSize(new Dimension(WIDTH, 150));
    for ( int i=0; i<table.getColumnCount(); i++ ) {
        TableColumn tm = table.getColumnModel().getColumn(i);
        tm.setCellRenderer(new ColorRenderer());
    }


    if (DEBUG) {
        table.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                printDebugData(table);
            }
        });
    }

    //setLayout(new GridLayout(5, 0));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);

    //create a add value button
    JPanel addpanel = new JPanel();
    addpanel.setPreferredSize(new Dimension(WIDTH,30));
    addpanel.add(createButton("Add","add"));
    addpanel.add(txtAddKey);
    addpanel.add(txtAddValue);
    addpanel.setMaximumSize(new Dimension(WIDTH,30));
    add(addpanel);

    //create a remove value button
    JPanel removepanel = new JPanel( );
    removepanel.setPreferredSize(new Dimension(WIDTH,30));
    removepanel.add(createButton("Remove","remove"));
    removepanel.add(txtRemoveKey);
    removepanel.setMaximumSize(new Dimension(WIDTH,30));
    add(removepanel);

    //create a change value button
    JPanel changepanel = new JPanel( );
    changepanel.add(createButton("Change","change"));
    changepanel.add(txtChangeKey);
    changepanel.add(txtChangeValue);
    changepanel.setPreferredSize(new Dimension(WIDTH,30));
    changepanel.setMaximumSize(new Dimension(WIDTH,30));
    add(changepanel);


    //create sync button
    JPanel syncpanel = new JPanel( );
    syncpanel.add(createButton("Synchronize","sync"));
    syncpanel.add(createButton("Replicate","replicate"));
    syncpanel.add(createButton("Random","random"));
    syncpanel.setPreferredSize(new Dimension(WIDTH,30));
    syncpanel.setMaximumSize(new Dimension(WIDTH,30));
    add(syncpanel);


}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:73,代码来源:MapDemo.java

示例10: setup

import javax.swing.JTable; //导入方法依赖的package包/类
private void setup(Class<U> protoScript, String entityDisplayName)
{
	JButton add = new JButton(addAction);
	JButton remove = new JButton(removeAction);

	model = new MyTableModel<T, U>(cache, protoScript, entityDisplayName);

	table = new JTable(model);
	table.addMouseListener(new TablePopupListener(table, addAction, removeAction));

	ListSelectionModel selModel = table.getSelectionModel();
	selModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
	selModel.addListSelectionListener(new ListSelectionListener()
	{
		@Override
		public void valueChanged(ListSelectionEvent e)
		{
			removeAction.update();
		}
	});

	TableColumn c1 = table.getColumnModel().getColumn(1);
	c1.setCellRenderer(new ScriptingTableCellRenderer(model));
	c1.setCellEditor(new ScriptingCellEditor(this, clientService, model));

	final int height1 = add.getPreferredSize().height;
	final int width1 = remove.getPreferredSize().width;

	final int[] rows = {TableLayout.FILL, height1,};
	final int[] cols = {TableLayout.FILL, width1, width1,};

	setLayout(new TableLayout(rows, cols));

	add(new JScrollPane(table), new Rectangle(0, 0, 3, 1));

	add(add, new Rectangle(1, 1, 1, 1));
	add(remove, new Rectangle(2, 1, 1, 1));

	changeDetector = new ChangeDetector();
	changeDetector.watch(model);
}
 
开发者ID:equella,项目名称:Equella,代码行数:42,代码来源:EntityWhereEditor.java

示例11: createWrapperList

import javax.swing.JTable; //导入方法依赖的package包/类
private JComponent createWrapperList()
{
	wrapperModel = new WrapperTableModel();
	wrapperList = new JTable();

	// Dodgy hack to get Checkboxes in table to display
	// with native L&F without changing to flatter L&F.
	// There are probably millions of ways to avoid this,
	// but I can't find any.
	// see Jira Defect TLE-2082 :
	// http://apps.dytech.com.au/jira/browse/TLE-2082
	UIManager.addPropertyChangeListener(new PropertyChangeListener()
	{
		@Override
		public void propertyChange(PropertyChangeEvent evt)
		{
			try
			{
				wrapperList.updateUI();
			}
			catch( Exception ex )
			{
				// Ignore
			}
		}
	});

	wrapperList.setModel(wrapperModel);
	wrapperList.getColumnModel().getColumn(1).setCellRenderer(new OverrideRenderer());

	wrapperList.addMouseListener(this);
	wrapperList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	JScrollPane scroll = new JScrollPane(wrapperList);
	JPanel panel = new JPanel(new TableLayout(new int[]{TableLayout.FILL, TableLayout.PREFERRED},
		new int[]{TableLayout.FILL}));
	panel.add(scroll, new Rectangle(0, 0, 1, 1));
	panel.add(createWrapperSelectButtons(), new Rectangle(0, 1, 1, 1));

	return panel;
}
 
开发者ID:equella,项目名称:Equella,代码行数:42,代码来源:AdminToolSelect.java

示例12: setup

import javax.swing.JTable; //导入方法依赖的package包/类
private void setup()
{
	actions = new ArrayList<TLEAction>();
	actions.add(upAction);
	actions.add(downAction);
	actions.add(addAction);
	actions.add(removeAction);

	model = new PowerSearchModel(repository);
	table = new JTable(model)
	{
		private static final long serialVersionUID = 1L;

		@Override
		public boolean getScrollableTracksViewportHeight()
		{
			// fetch the table's parent
			Container viewport = getParent();

			// if the parent is not a viewport, calling this isn't useful
			if( !(viewport instanceof JViewport) )
			{
				return false;
			}

			// return true if the table's preferred height is smaller
			// than the viewport height, else false
			return getPreferredSize().height < viewport.getHeight();
		}
	};
	table.setShowGrid(false);
	table.addMouseListener(new TablePopupListener(table, actions));
	table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	addListSelectionListener(new ListSelectionListener()
	{
		@Override
		public void valueChanged(ListSelectionEvent e)
		{
			if( !e.getValueIsAdjusting() )
			{
				updateButtons();
			}
		}
	});

	TableColumn c = table.getColumnModel().getColumn(1);
	c.setMinWidth(50);
	c.setMaxWidth(50);
	c.setWidth(50);

	JScrollPane tableScroll = new JScrollPane(table);

	JButton addButton = new JButton(addAction);
	JButton removeButton = new JButton(removeAction);
	JButton upButton = new JTextlessButton(upAction);
	JButton downButton = new JTextlessButton(downAction);

	final int height1 = upButton.getPreferredSize().height;
	final int height2 = removeButton.getPreferredSize().height;
	final int width1 = upButton.getPreferredSize().width;
	final int width2 = removeButton.getPreferredSize().width;

	final int[] rows = {TableLayout.FILL, height1, height1, TableLayout.FILL, height2,};
	final int[] cols = {width1, TableLayout.FILL, width2, width2, TableLayout.FILL,};

	setLayout(new TableLayout(rows, cols, 5, 5));

	add(tableScroll, new Rectangle(1, 0, 4, 4));
	add(upButton, new Rectangle(0, 1, 1, 1));
	add(downButton, new Rectangle(0, 2, 1, 1));
	add(addButton, new Rectangle(2, 4, 1, 1));
	add(removeButton, new Rectangle(3, 4, 1, 1));

	updateButtons();

	changeDetector = new ChangeDetector();
	changeDetector.watch(model);
}
 
开发者ID:equella,项目名称:Equella,代码行数:80,代码来源:PowerSearchList.java

示例13: setupGUI

import javax.swing.JTable; //导入方法依赖的package包/类
@SuppressWarnings("nls")
private void setupGUI(Node privNode, PrivilegeList accessModel)
{
	JButton add = new JButton(addAction);
	JButton remove = new JButton(removeAction);
	JButton up = new JTextlessButton(upAction);
	JButton down = new JTextlessButton(downAction);

	privilegeModel = new MyTableModel(privNode, accessModel);
	privilegeTable = new JTable(privilegeModel);
	privilegeTable.addMouseListener(new TablePopupListener(privilegeTable, actions));

	ListSelectionModel selectionModel = privilegeTable.getSelectionModel();
	selectionModel.addListSelectionListener(this);
	selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

	TableColumn actionColumn = privilegeTable.getColumnModel().getColumn(0);
	actionColumn.setCellRenderer(new ActionTableCellRenderer());
	actionColumn.setCellEditor(new ActionTableCellEditor());

	TableColumn whoColumn = privilegeTable.getColumnModel().getColumn(1);
	whoColumn.setCellRenderer(new ExpressionTableCellRenderer(userService));
	whoColumn.setCellEditor(new WhoTableCellEditor(userService, this));

	JScrollPane scroller = new JScrollPane(privilegeTable);

	final int height1 = add.getPreferredSize().height;
	final int width1 = remove.getPreferredSize().width;
	final int[] rows = {height1, height1, height1, height1, TableLayout.FILL,};
	final int[] cols = {TableLayout.FILL, width1,};

	JPanel all = new JPanel(new TableLayout(rows, cols));
	all.add(scroller, new Rectangle(0, 0, 1, 5));
	all.add(add, new Rectangle(1, 0, 1, 1));
	all.add(remove, new Rectangle(1, 1, 1, 1));
	all.add(up, new Rectangle(1, 2, 1, 1));
	all.add(down, new Rectangle(1, 3, 1, 1));

	showOverrides = new JCheckBox(
		CurrentLocale.get("com.tle.admin.security.editors.advancededitorpanel.overriding"));
	showDefaults = new JCheckBox(CurrentLocale.get("com.tle.admin.security.editors.advancededitorpanel.default"));

	showOverrides.addActionListener(this);
	showDefaults.addActionListener(this);

	final int mainHeight1 = showOverrides.getPreferredSize().height;
	final int[] mainRows = {TableLayout.INVISIBLE, TableLayout.FILL, TableLayout.INVISIBLE, mainHeight1,};
	final int[] mainCols = {TableLayout.FILL, TableLayout.FILL, width1,};
	layout = new TableLayout(mainRows, mainCols);
	setLayout(layout);

	add(new JLabel(CurrentLocale.get("com.tle.admin.security.editors.advancededitorpanel.overrides")),
		new Rectangle(2, 0, 1, 1));
	add(all, new Rectangle(0, 1, 3, 1));
	add(new JLabel(CurrentLocale.get("com.tle.admin.security.editors.advancededitorpanel.defaults")),
		new Rectangle(2, 2, 1, 1));
	add(showOverrides, new Rectangle(0, 3, 1, 1));
	add(showDefaults, new Rectangle(1, 3, 1, 1));

	updateButtons();
}
 
开发者ID:equella,项目名称:Equella,代码行数:62,代码来源:AdvancedEditorPanel.java

示例14: TablePasteAdapter

import javax.swing.JTable; //导入方法依赖的package包/类
/**
 * The TablePasteAdapter is constructed with a JTable on which it enables
 * Paste and acts as a Clipboard listener.
 */
private TablePasteAdapter(final JTable table)
{
	this.table = table;

	// Try getting the table model
	TableModel theirModel = table.getModel();
	if( theirModel instanceof TablePasteModel )
	{
		model = (TablePasteModel) theirModel;
	}
	else if( theirModel instanceof DefaultTableModel )
	{
		model = new DefaultTableModelAdapter((DefaultTableModel) theirModel);
	}
	else
	{
		throw new ClassCastException("Table model must implement TablePasteModel or extend DefaultTableModel"); //$NON-NLS-1$
	}

	// Register [Ctrl] + [C] for copy.
	KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
		false);
	table.registerKeyboardAction(this, "Copy", copy, JComponent.WHEN_FOCUSED); //$NON-NLS-1$
	// Register [Ctrl] + [V] for paste.
	KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
		false);
	table.registerKeyboardAction(this, "Paste", paste, JComponent.WHEN_FOCUSED); //$NON-NLS-1$

	// Get a reference to the clipboard
	clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

	// Set some defaults..
	setSelectOnPaste(true);

	// Setup converters.
	converters = new HashMap<Class<?>, DataConverter>();
	register(Boolean.class, new BooleanConverter());

	// Ensure that we can still paste into empty tables
	table.addMouseListener(new MouseAdapter()
	{
		@Override
		public void mousePressed(MouseEvent e)
		{
			if( e.isConsumed() || !table.isEnabled() || !SwingUtilities.isLeftMouseButton(e) )
			{
				return;
			}

			// if the UI ignores our desparate plea for focus when
			// the table is clicked beyond the last row or last column,
			// we'll try to grab focus anyway so that CTRL-V works
			int row = table.rowAtPoint(e.getPoint());
			int column = table.columnAtPoint(e.getPoint());
			if( row == -1 || column == -1 )
			{
				if( !table.hasFocus() && table.isRequestFocusEnabled() )
				{
					table.requestFocus();
				}
			}
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:69,代码来源:TablePasteAdapter.java

示例15: install

import javax.swing.JTable; //导入方法依赖的package包/类
public static void install(JTable table) {
    TableCellDrag tcellDrag = new TableCellDrag();
    table.addMouseListener(tcellDrag);
    table.addMouseMotionListener(tcellDrag);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:6,代码来源:TableCellDrag.java


注:本文中的javax.swing.JTable.addMouseListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。