List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:SecretTest.java
public SecretLabel(String msg) { super(msg);/* w w w . ja va 2 s . c o m*/ addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { fireActionPerformed( new ActionEvent(SecretLabel.this, ActionEvent.ACTION_PERFORMED, "SecretMessage")); } }); }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Gives a component a popup menu/*from w ww. j a v a 2s. c o m*/ * * @param component * The target component * @param popup * The popup menu */ public static void setPopupMenu(final JComponent component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { // Ignore mouse buttons outside of the normal range. This // fixes problems with trackpad scrolling. if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { // Ignore mouse buttons outside of the normal range. This // fixes problems with trackpad scrolling. if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } }); }
From source file:Main.java
public static JPopupMenu createStdEditPopupMenu(final JTextComponent[] fields) { final JPopupMenu popupMenu = new JPopupMenu(); /* text fields popup menu: "Cut" */ final JMenuItem cutMenuItem = new JMenuItem("Cut", 't'); cutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final Component c = popupMenu.getInvoker(); if (c instanceof JTextComponent) { ((JTextComponent) c).cut(); }/* w w w . ja v a 2 s.c o m*/ } }); popupMenu.add(cutMenuItem); /* text fields popup menu: "Copy" */ final JMenuItem copyMenuItem = new JMenuItem("Copy", 'C'); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final Component c = popupMenu.getInvoker(); if (c instanceof JTextComponent) { ((JTextComponent) c).copy(); } } }); popupMenu.add(copyMenuItem); /* text fields popup menu: "Paste" */ final JMenuItem pasteMenuItem = new JMenuItem("Paste", 'P'); pasteMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final Component c = popupMenu.getInvoker(); if (c instanceof JTextComponent) { ((JTextComponent) c).paste(); } } }); popupMenu.add(pasteMenuItem); popupMenu.addSeparator(); /* text fields popup menu: "Select All" */ final JMenuItem selectAllMenuItem = new JMenuItem("Select All", 'A'); selectAllMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final Component c = popupMenu.getInvoker(); if (c instanceof JTextComponent) { ((JTextComponent) c).selectAll(); } } }); popupMenu.add(selectAllMenuItem); /* add mouse listeners to the specified fields */ for (final JTextComponent f : fields) { f.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { processMouseEvent(e); } @Override public void mouseReleased(MouseEvent e) { processMouseEvent(e); } private void processMouseEvent(MouseEvent e) { if (e.isPopupTrigger()) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); popupMenu.setInvoker(f); } } }); } return popupMenu; }
From source file:CheckBoxList.java
public CheckBoxList() { super();/*from ww w.j a v a 2 s .co m*/ setModel(new DefaultListModel()); setCellRenderer(new CheckboxCellRenderer()); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); if (index != -1) { Object obj = getModel().getElementAt(index); if (obj instanceof JCheckBox) { JCheckBox checkbox = (JCheckBox) obj; checkbox.setSelected(!checkbox.isSelected()); repaint(); } } } } ); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
From source file:Main.java
public KeyTextComponent() { setBackground(Color.cyan);//from w ww. ja v a2 s .co m KeyListener internalKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (actionListenerList != null) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText); actionListenerList.actionPerformed(actionEvent); } } }; MouseListener internalMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { requestFocus(); } }; addKeyListener(internalKeyListener); addMouseListener(internalMouseListener); }
From source file:ColorSource.java
/** Create a new ColorSource object that displays the speciifed color */ public ColorSource(Color color) { // Save the color. Encapsulate it in a Transferable object so that // it can be used with cut-and-paste and drag-and-drop this.color = color; this.tcolor = new TransferableColor(color); // Set our default border this.setBorder(defaultBorder); // Listen for mouse clicks, and copy the color to the clipboard. this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { copy();/*from w w w . ja v a 2 s .c o m*/ } }); // Set up a DragGestureRecognizer that will detect when the user // begins a drag. When it detects one, it will notify us by calling // the dragGestureRecognized() method of the DragGestureListener // interface we implement below this.dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, // Look for drags on us DnDConstants.ACTION_COPY_OR_MOVE, // Recognize these types this); // Tell us when recognized }
From source file:MainClass.java
public KeyTextComponent() { setBackground(Color.CYAN);/*from w w w. j a v a2 s. c o m*/ KeyListener internalKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (actionListenerList != null) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, keyText); fireActionPerformed(actionEvent); } } }; MouseListener internalMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { requestFocusInWindow(); } }; addKeyListener(internalKeyListener); addMouseListener(internalMouseListener); }
From source file:Main.java
public KeyTextComponent() { setBackground(Color.CYAN);/*w ww. j av a 2 s . co m*/ KeyListener internalKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (actionListenerList != null) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_LAST, keyText); fireActionPerformed(actionEvent); } } }; MouseListener internalMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { requestFocusInWindow(); } }; addKeyListener(internalKeyListener); addMouseListener(internalMouseListener); }
From source file:Main.java
public KeyTextComponent() { setBackground(Color.CYAN);//from w ww .j a v a 2 s . c o m KeyListener internalKeyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (actionListenerList != null) { int keyCode = keyEvent.getKeyCode(); String keyText = KeyEvent.getKeyText(keyCode); ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_FIRST, keyText); fireActionPerformed(actionEvent); } } }; MouseListener internalMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { requestFocusInWindow(); } }; addKeyListener(internalKeyListener); addMouseListener(internalMouseListener); }