List of usage examples for java.awt.event MouseEvent getButton
public int getButton()
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane editorPane = new JTextPane(); editorPane.setSelectedTextColor(Color.red); // set content as html // editorPane.setContentType("text/html"); editorPane.setText("<p color='#FF0000'>Cool!</p>"); // added <u></u> to underlone button JButton label = new JButton("button"); label.setAlignmentY(0.85f);/*from w w w .j a v a 2s . c om*/ label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) { JOptionPane.showMessageDialog(null, "Hello!"); } } }); editorPane.insertComponent(label); frame.getContentPane().add(editorPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] items = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" }; JList<String> myJList = new JList(items) { @Override//from ww w.ja va 2 s. c o m protected void processMouseEvent(MouseEvent e) { int modifiers = e.getModifiers() | InputEvent.CTRL_MASK; int modifiersEx = e.getModifiersEx() | InputEvent.CTRL_MASK; MouseEvent myME = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), modifiers, e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton()); super.processMouseEvent(myME); } }; JFrame f = new JFrame(); f.add(new JScrollPane(myJList)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:com.qawaa.gui.PointAnalysisGUI.java
/** * Auto-generated main method to display this JFrame *//*from w ww . j a v a 2 s . c o m*/ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { PointAnalysisGUI inst = new PointAnalysisGUI(); inst.setLocationRelativeTo(null); inst.setVisible(true); inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFrame.setDefaultLookAndFeelDecorated(true); FlowLayout flowLayout = new FlowLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setAlignOnBaseline(true); inst.setTitle(PROGRAM_NAME + " [" + PROGRAM_VERSION + "] " + " - " + DefaultMessage.SOFT_NAME + " - " + DefaultMessage.COMPANY_NAME); { consoleScrollPane = new JScrollPane(); inst.getContentPane().add(consoleScrollPane, BorderLayout.CENTER); { consolePane = new JEditorPane(); consoleScrollPane.setViewportView(consolePane); consolePane.setText(""); setConsoleRight(); jConsole = new JConsole(System.out, consolePane); System.setOut(jConsole); System.setErr(jConsole); consolePane.setEditable(false); consolePane.addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { consolePane.add(consoleRight); consoleRight.show(e.getComponent(), e.getX(), e.getY()); } } }); } } { infoPanel = new JPanel(); inst.getContentPane().add(infoPanel, BorderLayout.SOUTH); infoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 1, false)); infoPanel.setPreferredSize(new Dimension(784, 30)); infoPanel.setLayout(flowLayout); { { statusbar_count = new JTextPane(); infoPanel.add(statusbar_count); statusbar_count .setText(CONTEXT.getMessage("point.statusbar.count", null, Locale.CHINA)); statusbar_count.setBackground(null); statusbar_count.setEditable(false); } { statusbar_count_value = new JTextPane(); infoPanel.add(statusbar_count_value); statusbar_count_value.setText(String.valueOf(SCAN_COUNT)); statusbar_count_value.setBackground(null); statusbar_count_value.setEditable(false); statusbar_count_value.setEnabled(false); } { programPID = new JTextPane(); infoPanel.add(programPID); programPID.setText("PID:"); programPID.setBackground(null); programPID.setEditable(false); } { programPID_value = new JTextPane(); infoPanel.add(programPID_value); programPID_value.setText(JvmPid.getPID()); programPID_value.setBackground(null); programPID_value.setEditable(false); programPID_value.setEnabled(false); } { memory = new JTextPane(); infoPanel.add(memory); memory.setText(CONTEXT.getMessage("gobal.gui.memory", null, Locale.CHINA)); memory.setBackground(null); memory.setEditable(false); } { memory_value = new JTextPane(); infoPanel.add(memory_value); memory_value.setText("0KB"); memory_value.setBackground(null); memory_value.setEditable(false); memory_value.setEnabled(false); MemoryListener memory = new MemoryListener(memory_value); memory.start(); } { runtime = new JTextPane(); infoPanel.add(runtime); runtime.setText(CONTEXT.getMessage("gobal.gui.runtime", null, Locale.CHINA)); runtime.setBackground(null); runtime.setEditable(false); } { runtime_value = new JTextPane(); infoPanel.add(runtime_value); runtime_value.setText("NULL"); runtime_value.setBackground(null); runtime_value.setEditable(false); runtime_value.setEnabled(false); } } } { shortcut = new JPanel(); inst.getContentPane().add(shortcut, BorderLayout.NORTH); shortcut.setSize(784, 35); shortcut.setPreferredSize(new Dimension(784, 35)); shortcut.setBorder(new LineBorder(new Color(0, 0, 0), 1, false)); shortcut.setLayout(new BorderLayout()); { eventText = new JTextPane(); shortcut.add(eventText, BorderLayout.WEST); eventText.setText(CONTEXT.getMessage("point.event.name", null, Locale.CHINA) + ": "); eventText.setEditable(false); eventText.setEnabled(true); eventText.setBackground(null); eventText.setCaretColor(new Color(0, 0, 0)); } { eventTextField = new JTextField(); shortcut.add(eventTextField, BorderLayout.CENTER); eventTextField.setSize(500, 25); eventTextField.setText(""); eventTextField.setPreferredSize(new Dimension(500, 25)); eventTextField.setEditable(false); } { submit = new JButton(); shortcut.add(submit, BorderLayout.EAST); submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA)); submit.setSize(new Dimension(75, 25)); submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { submitActionPerformed(evt); } catch (InterruptedException e) { e.printStackTrace(); } } }); } } } }); }
From source file:com.qawaa.gui.EventWebScanGUI.java
/** * Auto-generated main method to display this JFrame *//*from www.jav a 2 s . co m*/ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { EventWebScanGUI inst = new EventWebScanGUI(); inst.setLocationRelativeTo(null); inst.setVisible(true); inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFrame.setDefaultLookAndFeelDecorated(true); FlowLayout flowLayout = new FlowLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setAlignOnBaseline(true); inst.setTitle(PROGRAM_NAME + " [" + PROGRAM_VERSION + "] " + " - " + DefaultMessage.SOFT_NAME + " - " + DefaultMessage.COMPANY_NAME); { consoleScrollPane = new JScrollPane(); inst.getContentPane().add(consoleScrollPane, BorderLayout.CENTER); { consolePane = new JEditorPane(); consoleScrollPane.setViewportView(consolePane); consolePane.setText(""); setConsoleRight(); jConsole = new JConsole(System.out, consolePane); System.setOut(jConsole); System.setErr(jConsole); consolePane.setEditable(false); consolePane.addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent) */ public void mouseReleased(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { consolePane.add(consoleRight); consoleRight.show(e.getComponent(), e.getX(), e.getY()); } } }); } } { infoPanel = new JPanel(); inst.getContentPane().add(infoPanel, BorderLayout.SOUTH); infoPanel.setBorder(new LineBorder(new Color(0, 0, 0), 1, false)); infoPanel.setPreferredSize(new Dimension(784, 30)); infoPanel.setLayout(flowLayout); { { statusbar_count = new JTextPane(); infoPanel.add(statusbar_count); statusbar_count.setText( CONTEXT.getMessage("event.web.scan.statusbar.count", null, Locale.CHINA)); statusbar_count.setBackground(null); statusbar_count.setEditable(false); } { statusbar_count_value = new JTextPane(); infoPanel.add(statusbar_count_value); statusbar_count_value.setText(String.valueOf(SCAN_COUNT)); statusbar_count_value.setBackground(null); statusbar_count_value.setEditable(false); statusbar_count_value.setEnabled(false); } { programPID = new JTextPane(); infoPanel.add(programPID); programPID.setText("PID:"); programPID.setBackground(null); programPID.setEditable(false); } { programPID_value = new JTextPane(); infoPanel.add(programPID_value); programPID_value.setText(JvmPid.getPID()); programPID_value.setBackground(null); programPID_value.setEditable(false); programPID_value.setEnabled(false); } { memory = new JTextPane(); infoPanel.add(memory); memory.setText(CONTEXT.getMessage("gobal.gui.memory", null, Locale.CHINA)); memory.setBackground(null); memory.setEditable(false); } { memory_value = new JTextPane(); infoPanel.add(memory_value); memory_value.setText("0KB"); memory_value.setBackground(null); memory_value.setEditable(false); memory_value.setEnabled(false); MemoryListener memory = new MemoryListener(memory_value); memory.start(); } { runtime = new JTextPane(); infoPanel.add(runtime); runtime.setText(CONTEXT.getMessage("gobal.gui.runtime", null, Locale.CHINA)); runtime.setBackground(null); runtime.setEditable(false); } { runtime_value = new JTextPane(); infoPanel.add(runtime_value); runtime_value.setText("NULL"); runtime_value.setBackground(null); runtime_value.setEditable(false); runtime_value.setEnabled(false); } } } { shortcut = new JPanel(); inst.getContentPane().add(shortcut, BorderLayout.NORTH); shortcut.setSize(784, 35); shortcut.setPreferredSize(new Dimension(784, 35)); shortcut.setBorder(new LineBorder(new Color(0, 0, 0), 1, false)); shortcut.setLayout(new BorderLayout()); { eventText = new JTextPane(); shortcut.add(eventText, BorderLayout.WEST); eventText.setText(CONTEXT.getMessage("event.web.scan.name", null, Locale.CHINA) + ": "); eventText.setEditable(false); eventText.setEnabled(true); eventText.setBackground(null); eventText.setCaretColor(new Color(0, 0, 0)); } { eventTextField = new JTextField(); shortcut.add(eventTextField, BorderLayout.CENTER); eventTextField.setSize(500, 25); eventTextField.setText(""); eventTextField.setPreferredSize(new Dimension(500, 25)); eventTextField.setEditable(false); } { submit = new JButton(); shortcut.add(submit, BorderLayout.EAST); submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA)); submit.setSize(new Dimension(75, 25)); submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { submitActionPerformed(evt); } catch (InterruptedException e) { e.printStackTrace(); } } }); } } } }); }
From source file:Main.java
public static void main(String[] args) { final JTabbedPane jTabbedPane = new JTabbedPane(); jTabbedPane.addTab("Red", new JLabel("Roses")); jTabbedPane.addTab("Blue", new JLabel("Skies")); jTabbedPane.addTab("Green", new JLabel("Grass")); for (int i = 0; i < jTabbedPane.getTabCount(); i++) { final JLabel tabComponent = new JLabel(jTabbedPane.getTitleAt(i)); tabComponent.addMouseMotionListener(new MouseMotionAdapter() { @Override//from ww w . j a v a2 s .c o m public void mouseDragged(MouseEvent e) { System.out.println("tabComponent dragging"); } }); tabComponent.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int x = tabComponent.getLocationOnScreen().x - jTabbedPane.getLocationOnScreen().x; int y = tabComponent.getLocationOnScreen().y - jTabbedPane.getLocationOnScreen().y; MouseEvent me = new MouseEvent((JLabel) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), x, y, e.getLocationOnScreen().x, e.getLocationOnScreen().y, e.getClickCount(), e.isPopupTrigger(), e.getButton()); jTabbedPane.getMouseListeners()[0].mousePressed(me); System.out.println("tabComponent mousePressed e=" + e); } }); jTabbedPane.setTabComponentAt(i, tabComponent); } JFrame jFrame = new JFrame(); jFrame.add(jTabbedPane); jFrame.setSize(400, 500); jFrame.setVisible(true); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
/** * Check to see if the event is for the left mouse button and the Alt key is pressed. * Also allows the right mouse button with the control key down. This is so it can * work via Citrix Receiver./*from ww w. j av a 2 s. com*/ * * @param event * @return */ static boolean isLeftButtonAndAltDown(final MouseEvent event) { if (event.getButton() == MouseEvent.BUTTON1) { return isAltDown(event); } else if (event.getButton() == MouseEvent.BUTTON3) { return isControlDown(event); } else { return false; } }
From source file:Main.java
public static MouseEvent convertMouseEvent(MouseEvent e, Component newSource, Point newPoint) { return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiersEx(), newPoint.x, newPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void addDoubleClickListener(JComponent component, final DoubleClickListener listener) { assert listener != null; component.addMouseListener(new MouseAdapter() { @Override/*from w ww .ja v a 2 s . co m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) { listener.mouseClicked(e); } } }); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void addDoubleClickAction(JComponent component, final Action action) { component.addMouseListener(new MouseAdapter() { @Override/* www. j av a 2s . c o m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == DOUBLE_CLICK_COUNT && e.getButton() == MouseEvent.BUTTON1) { action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, (String) action.getValue(Action.ACTION_COMMAND_KEY), e.getWhen(), e.getModifiers())); } } }); }
From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerUtil.java
/** * Creates a {@link MouseListener} to open the selected log folder in MRA. * //from www . j a va2 s . c om * @param worker * @param logFolderList * @return */ static MouseAdapter createOpenLogInMRAMouseListener(LogsDownloaderWorker worker, LogFolderInfoList logFolderList) { return new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { // Test if log can be opened in MRA, and open it final String baseFxPath = worker.getDirBaseToStoreFiles() + "/" + worker.getLogLabel() + "/" + logFolderList.getSelectedValue() + "/"; File logFolder = new File(baseFxPath); LogValidity isLogOkForOpening = LogUtils.isValidLSFSource(logFolder); JPopupMenu popup = new JPopupMenu(); JMenuItem jm = popup.add(I18n.text("Open this log in MRA")); if (isLogOkForOpening == LogValidity.VALID) { File log = LogUtils.getValidLogFileFromLogFolder(logFolder); jm.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Thread t = new Thread( LogsDownloaderWorker.class.getSimpleName() + " :: MRA Openner") { public void run() { JFrame mra = new NeptusMRA(); mra.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); ((NeptusMRA) mra).getMraFilesHandler().openLog(log); }; }; t.setDaemon(true); t.start(); } }); } else { jm.setEnabled(false); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } }; }