Example usage for java.awt.event MouseEvent getX

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

Introduction

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

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

From source file:LayeredPaneDemo.java

public void mouseMoved(MouseEvent e) {
    dukeLabel.setLocation(e.getX() - XFUDGE, e.getY() - YFUDGE);
}

From source file:components.LayeredPaneDemo2.java

public void mouseMoved(MouseEvent e) {
    dukeLabel.setLocation(e.getX() - dukeLabel.getWidth() / 2, e.getY() - dukeLabel.getHeight() / 2);
}

From source file:Main.java

public Main(JTree jt) {
    super();/*from ww w  .ja va2s. c  o  m*/
    tree = jt;
    getContentPane().add(tree);
    tree.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            if (((event.getModifiers() & InputEvent.BUTTON3_MASK) != 0) && (tree.getSelectionCount() > 0)) {
                showMenu(event.getX(), event.getY());
            }
        }
    });
}

From source file:Main.java

public void mouseClicked(MouseEvent evt) {
    JTable table = ((JTableHeader) evt.getSource()).getTable();
    TableColumnModel colModel = table.getColumnModel();

    int index = colModel.getColumnIndexAtX(evt.getX());
    if (index == -1) {
        return;/* w w  w .  j av  a2 s. c o m*/
    }
    Rectangle headerRect = table.getTableHeader().getHeaderRect(index);
    if (index == 0) {
        headerRect.width -= 10;
    } else {
        headerRect.grow(-10, 0);
    }
    if (!headerRect.contains(evt.getX(), evt.getY())) {
        int vLeftColIndex = index;
        if (evt.getX() < headerRect.x) {
            vLeftColIndex--;
        }
    }
}

From source file:UndoManagerDemo.java

public UndoManagerDemo() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);// w  w  w .jav  a2 s .c o  m
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(canvas, BorderLayout.CENTER);

    canvas.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point point = new Point(e.getX(), e.getY());
            pointVector.addElement(point);

            undoManager.undoableEditHappened(
                    new UndoableEditEvent(canvas, new UndoablePaintSquare(point, pointVector)));

            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
            canvas.repaint();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mouseDragged(Canvas canvas, MouseEvent e) {
    updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
}

From source file:com.cburch.draw.tools.LineTool.java

@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    int mods = e.getModifiersEx();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        x = canvas.snapX(x);/*  ww w  .ja  va  2 s. com*/
        y = canvas.snapY(y);
    }
    Location loc = Location.create(x, y);
    mouseStart = loc;
    mouseEnd = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas);
}

From source file:components.ScrollablePicture.java

public void mouseDragged(MouseEvent e) {
    //The user is dragging us, so scroll!
    Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
    scrollRectToVisible(r);//ww  w.j ava2  s  .com
}

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}/*from   ww w  . j a  va 2 s.  c o m*/
 */
@Override
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    final ChartEntity entity = getEntityForPoint(e.getX(), e.getY());
    if (entity instanceof PieSectionEntity) {
        source = (PieSectionEntity) entity;
    }
    released = false;
}

From source file:layout.BLDComponent.java

public void mousePressed(MouseEvent e) {
    int width = getWidth();
    float alignment = (float) (e.getX()) / (float) width;

    // Round to the nearest 1/10th.
    int tmp = Math.round(alignment * 10.0f);
    alignment = (float) tmp / 10.0f;

    setAlignmentX(alignment);/*from   w  ww  .  j a v  a2 s  .com*/
    revalidate(); // this GUI needs relayout
    repaint();
}