Example usage for javax.swing JComponent setCursor

List of usage examples for javax.swing JComponent setCursor

Introduction

In this page you can find the example usage for javax.swing JComponent setCursor.

Prototype

public void setCursor(Cursor cursor) 

Source Link

Document

Sets the cursor image to the specified cursor.

Usage

From source file:net.panthema.BispanningGame.MyEditingGraphMousePlugin.java

public void mouseEntered(MouseEvent e) {
    JComponent c = (JComponent) e.getSource();
    c.setCursor(cursor);
}

From source file:net.panthema.BispanningGame.MyEditingGraphMousePlugin.java

public void mouseExited(MouseEvent e) {
    JComponent c = (JComponent) e.getSource();
    c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

From source file:org.eclipse.birt.chart.device.swing.SwingEventHandler.java

private void setCursor(JComponent composite, org.eclipse.birt.chart.model.attribute.Cursor cursor,
        Cursor defaultCursor) {/*from  ww  w  .  java  2s  .  c o  m*/
    if (cursor == null || cursor.getType() == CursorType.AUTO) {
        composite.setCursor(defaultCursor);
        return;
    } else if (cursor.getType() == CursorType.CUSTOM) {
        // Find the first valid image as custom cursor.
        EList<org.eclipse.birt.chart.model.attribute.Image> uris = cursor.getImage();
        for (org.eclipse.birt.chart.model.attribute.Image uri : uris) {
            try {
                Image image = null;
                if (uri instanceof EmbeddedImage) {
                    try {
                        byte[] data = Base64.decodeBase64(((EmbeddedImage) uri).getData().getBytes());

                        image = new ImageIcon(data).getImage();
                    } catch (Exception ilex) {
                        logger.log(ilex);
                    }
                } else {
                    URI u = new URI(uri.getURL());
                    image = composite.getToolkit().createImage(SecurityUtil.toURL(u));
                }

                if (image != null) {
                    composite.setCursor(composite.getToolkit().createCustomCursor(image, new Point(0, 0), ""));//$NON-NLS-1$
                    return;
                }
            } catch (URISyntaxException e) {
                // Do not process exception here.
            } catch (MalformedURLException e) {
                // Do not process exception here.
            }
        }

        // No valid image is found, set default cursor.
        composite.setCursor(defaultCursor);
        return;
    }

    composite.setCursor(Cursor.getPredefinedCursor(SwingHelper.CURSOR_MAP.get(cursor.getType()).intValue()));
}