Example usage for java.awt.event MouseEvent getLocationOnScreen

List of usage examples for java.awt.event MouseEvent getLocationOnScreen

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getLocationOnScreen.

Prototype

public Point getLocationOnScreen() 

Source Link

Document

Returns the absolute x, y position of the event.

Usage

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  w w  w . j  a  v  a 2s  .  com
            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

public Main() {
    setLayout(null);/*from   w  w  w  .j  ava2s  .  c  om*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            System.out.println(e.getLocationOnScreen());
        }
    });
}

From source file:Main.java

@Override
public void mousePressed(MouseEvent e) {
    JLabel label = (JLabel) e.getSource();
    initLabelLocation = label.getLocation();
    initMouseLocationOnScreen = e.getLocationOnScreen();
}

From source file:Main.java

@Override
public void mouseDragged(MouseEvent e) {
    if (initLabelLocation == null || initMouseLocationOnScreen == null) {
        return;/*from  ww w .  j  a  v a 2 s.  c  om*/
    }
    JLabel label = (JLabel) e.getSource();
    Point mouseLocation = e.getLocationOnScreen();
    int deltaX = mouseLocation.x - initMouseLocationOnScreen.x;
    int deltaY = mouseLocation.y - initMouseLocationOnScreen.y;
    int labelX = initLabelLocation.x + deltaX;
    int labelY = initLabelLocation.y + deltaY;
    label.setLocation(labelX, labelY);
}

From source file:Main.java

public Main() {
    setLayout(null);/*  w  ww. j ava  2 s . c  o m*/
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            int onmask = MouseEvent.SHIFT_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
            int offmask = MouseEvent.CTRL_DOWN_MASK;
            if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
                System.out.println(event.getLocationOnScreen());
            }
        }
    });
}

From source file:com.clough.android.adbv.view.UpdateTableDialog.java

private void resultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultTableMouseClicked
    // TODO add your handling code here:
    if (evt.getButton() == MouseEvent.BUTTON3) {
        int rowIndex;
        if ((rowIndex = validateRowSelection()) != -1) {
            showTableChangeOptionMenu(evt.getLocationOnScreen().x - getX(),
                    evt.getLocationOnScreen().y - getY(), rowIndex);
        }// w w w  .j a v a  2s . com
    }
}

From source file:ui.frame.KAIQRFrame.java

public KAIQRFrame() {
    // init frames
    super("KAI QR Code Generator");
    mouseDownCompCoords = null;//from w w  w .  java2 s  . co m
    addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
            mouseDownCompCoords = null;
        }

        public void mousePressed(MouseEvent e) {
            mouseDownCompCoords = e.getPoint();
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    addMouseMotionListener(new MouseMotionListener() {
        public void mouseMoved(MouseEvent e) {
        }

        public void mouseDragged(MouseEvent e) {
            Point currCoords = e.getLocationOnScreen();
            setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y);
        }
    });

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    menuPanel = p.createPanel(Layouts.grid, 5, 1);
    btnLogOut = b.createButton("Logout");
    btnLogOut.setPreferredSize(new Dimension(100, 50));
    btnLogOut.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            APICall api = new APICall();
            try {
                JSONObject response = new JSONObject(api.logout(Data.targetURL, Data.sessionKey));
                if (response.getString("result").equals("ok")) {
                    UILogin login = new UILogin();
                    Data.mainFrame.setVisible(false);
                }
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    });
    menuPanel.add(btnLogOut);

    cardPanel = p.createPanel(Layouts.card);
    cardLayout = new CardLayout();
    cardPanel.setLayout(cardLayout);

    getContentPane().setBackground(CustomColor.NavyBlue.returnColor());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    setLocationRelativeTo(null);
    add(menuPanel, BorderLayout.WEST);
    add(cardPanel, BorderLayout.CENTER);
    pack();
}

From source file:NewGUI.Statistics.java

private void tbListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbListMouseClicked
    // TODO add your handling code here:

    if (evt.getButton() == MouseEvent.BUTTON3) {
        Point point = evt.getLocationOnScreen();
        popupTable.setLocation(point);/*  w ww.  j ava  2 s  . co  m*/
        popupTable.setVisible(true);
    }
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

private JXTaskPane createLearnerFeedbackChartPane() {
    JXTaskPane feedbackChartPane = new JXTaskPane();
    feedbackChartPane.setScrollOnExpand(true);
    feedbackChartPane.setTitle("Learner Feedback");
    FeedbackChartMaker maker = new FeedbackChartMaker(module);
    final ChartPanel chartPanel = maker.getChartPanel();
    //Add a mouselistener, listening for a double click on a bar of the stacked bar
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override//from w ww .j a v  a 2 s  . c  o  m
        public void chartMouseClicked(ChartMouseEvent cme) {
            //Get the mouse event
            MouseEvent trigger = cme.getTrigger();
            //Test if the mouse event is a left-button
            if (trigger.getButton() == MouseEvent.BUTTON1 && trigger.getClickCount() == 2) {

                //Create a pop up dialog containing that the tlalineitems
                FeedbackPopupDialog popup = new FeedbackPopupDialog(
                        (Frame) SwingUtilities.getWindowAncestor(chartPanel), true, module.getTLALineItems());
                //Set the title of the popup 
                popup.setTitle("All Activities");
                //Centre the popup at the location of the mouse click
                Point location = trigger.getLocationOnScreen();
                int w = popup.getWidth();
                int h = popup.getHeight();
                popup.setLocation(location.x - w / 2, location.y - h / 2);
                popup.setVisible(true);
                int returnStatus = popup.getReturnStatus();
                if (returnStatus == LearningTypePopupDialog.RET_OK) {
                    modifyTLALineItem(popup.getSelectedTLALineItem(), 1);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //Set the cursor shape according to the location of the cursor
            if (cme.getEntity() instanceof CategoryItemEntity) {
                chartPanel.setCursor(HAND);
            } else {
                chartPanel.setCursor(Cursor.getDefaultCursor());
            }
        }
    });
    chartPanel.setPreferredSize(new Dimension(150, 200));
    feedbackChartPane.add(chartPanel);
    return feedbackChartPane;
}

From source file:savant.view.swing.GraphPane.java

/**
 * {@inheritDoc}//from   ww  w. j av  a 2s .co m
 */
@Override
public void mousePressed(MouseEvent event) {

    setMouseModifier(event);

    requestFocus();

    int x1 = getConstrainedX(event);

    baseX = transformXPixel(x1);
    initialScroll = getVerticalScrollBar().getValue();

    Point l = event.getLocationOnScreen();
    startX = l.x;
    startY = l.y;

    GraphPaneController gpc = GraphPaneController.getInstance();
    gpc.setMouseClickPosition(transformXPixel(x1));
}