Example usage for javax.swing JPanel addMouseMotionListener

List of usage examples for javax.swing JPanel addMouseMotionListener

Introduction

In this page you can find the example usage for javax.swing JPanel addMouseMotionListener.

Prototype

public synchronized void addMouseMotionListener(MouseMotionListener l) 

Source Link

Document

Adds the specified mouse motion listener to receive mouse motion events from this component.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame(Main.class.getSimpleName());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    BufferedImage bi = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel(new ImageIcon(bi));
    panel.add(label);//from   ww w  .j  a v a 2  s .c  om
    MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
        @Override
        public void mouseDragged(MouseEvent e) {
            Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
            ((JPanel) e.getSource()).scrollRectToVisible(r);
        }
    };
    panel.addMouseMotionListener(doScrollRectToVisible);

    panel.setAutoscrolls(true);
    f.add(new JScrollPane(panel));
    f.pack();
    f.setSize(f.getWidth() / 2, f.getHeight() / 2);
    f.setVisible(true);
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

/**
 * // www . j  a  va 2  s  .c  o m
 */
protected void showForm() {
    if (selectedForm != null) {
        if (formFrame != null) {
            formFrame.setVisible(false);
            formFrame.dispose();
        }

        formFrame = new JFrame();

        FormPanelInfo formPanelInfo = createPanel(selectedForm);
        JPanel panel = formPanelInfo.getPanel();

        JLabel label = new JLabel(formPanelInfo.getTitle(), SwingConstants.CENTER);
        Font font = label.getFont();

        label.setFont(font.deriveFont(14.0f).deriveFont(Font.BOLD));

        JPanel container = new JPanel(new BorderLayout());

        container.add(panel, BorderLayout.CENTER);
        container.add(label, BorderLayout.SOUTH);

        formFrame.setContentPane(container);

        panel.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                //System.out.println(e.getPoint());
            }
        });

        formFrame.setVisible(true);
        formFrame.setSize(new Dimension(formPanelInfo.getMaxWidth() + 10, formPanelInfo.getMaxHeight() + 25));
    }
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * Build a StatisticGrafic Instance/*from  w ww  .  j  a  v  a2 s.  com*/
 * @param statistic         The associated statistic instance
 * @param viewId         Id of view
 * @param pointExtern      Middle point 
 * @param typeAnimation      Default animation type. This can changed by popup menu.
 *                      For animation types look at StatisticGrafic.ANIMATION_... 
 * @param isIntValue      In typeAnimation == StatisticGrafic.ANIMATION_LastValue
 *                      value is shown as integer.
 * @param deltaSize         The default size can be incremented/decremented 
 *                      by deltaSize. Null means no change. 
 * @param infopane         Grafic is used for infopane 
 * @throws ModelException
 */
public StatisticGrafic(Statistic statistic, String viewId, Point pointExtern, int typeAnimation,
        boolean isIntValue, Dimension deltaSize, boolean infopane) throws ModelException {

    this.statistic = statistic;
    if (viewId == null)
        viewId = "main";
    this.viewId = viewId;
    //System.out.println("StatisticGrafic-Konstructor   id: "+this.statistic.getId());
    this.pointExtern = pointExtern;
    this.transform();
    this.setCode();
    this.setBorder(BorderFactory.createTitledBorder(Grafic.Border_Default, this.code,
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, Grafic.FONT_DEFAULT,
            Grafic.COLOR_BORDER));
    this.deltaSize = deltaSize;
    if (this.deltaSize == null)
        this.deltaSize = new Dimension(0, 0);
    this.typeAnimation = typeAnimation;
    this.isIntValue = isIntValue;
    JPanel content = new JPanel();
    switch (this.typeAnimation) {
    case StatisticGrafic.ANIMATION_LastValue:
        content = this.buildLastValuePanel();
        break;
    case StatisticGrafic.ANIMATION_TimeValueDiagram:
        content = this.buildTimeValueDiagramPanel();
        break;
    case StatisticGrafic.ANIMATION_Histogram:
        if (statistic.hasHistogramSupport())
            content = this.buildHistogramPanel();
        else {
            this.typeAnimation = StatisticGrafic.ANIMATION_TimeValueDiagram;
            content = this.buildTimeValueDiagramPanel();
        }
        break;
    }
    this.setLayout(new GridLayout(1, 1));
    this.add(content);
    this.setOpaque(true);
    Dimension d = new Dimension(content.getPreferredSize().width + this.deltaSize.width,
            content.getPreferredSize().height + this.deltaSize.height);
    this.setBounds(this.pointIntern.x - d.width / 2, this.pointIntern.y - d.height / 2, d.width, d.height);
    this.update();
    // Listener hinzufuegen
    if (this.statistic.getModel().getCoordinatenListener() != null) {
        this.addMouseMotionListener(this.statistic.getModel().getCoordinatenListener());
        this.addMouseListener(this.statistic.getModel().getCoordinatenListener());
        if (!infopane && this.typeAnimation != StatisticGrafic.ANIMATION_LastValue) {
            content.addMouseMotionListener(this.statistic.getModel().getCoordinatenListener());
            content.addMouseListener(this.statistic.getModel().getCoordinatenListener());
        }
    }
    this.addMouseListener(this);
}

From source file:op.FrmMain.java

public void setBlocked(boolean blocked) {
    if (blocked) {
        lblWait.setVisible(true);/*  w  w w . ja v  a  2 s .c o  m*/
        JPanel glass = new JPanel();
        glass.addMouseListener(new MouseAdapter() {
        });
        glass.addMouseMotionListener(new MouseMotionAdapter() {
        });
        glass.addKeyListener(new KeyAdapter() {
        });
        glass.setOpaque(false);
        setGlassPane(glass);
        getGlassPane().setVisible(true);
        ((CardLayout) pnlCard.getLayout()).show(pnlCard, "cardWait");
    } else {
        getGlassPane().setVisible(false);
        setGlassPane(new JPanel());
        ((CardLayout) pnlCard.getLayout()).show(pnlCard, "cardContent");
    }
}