Java ImageIcon createCursor(ImageIcon cursorIcon, Point hotSpot, String name)

Here you can find the source of createCursor(ImageIcon cursorIcon, Point hotSpot, String name)

Description

create Cursor

License

Open Source License

Declaration

public static Cursor createCursor(ImageIcon cursorIcon, Point hotSpot, String name) 

Method Source Code

//package com.java2s;
/*//from w w w.  j ava  2s  .  com
 *   Copyright (C) 2006  The Concord Consortium, Inc.,
 *   25 Love Lane, Concord, MA 01742
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Image;
import java.awt.Point;

import java.awt.Toolkit;

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    public static Cursor createCursor(URL url, Point hotSpot, String name) {
        return createCursor(new ImageIcon(url), hotSpot, name);
    }

    public static Cursor createCursor(ImageIcon cursorIcon, Point hotSpot, String name) {
        return createCursor(cursorIcon.getImage(), hotSpot, name);
    }

    public static Cursor createCursor(Image cursorImage, Point hotSpot, String name) {
        if (hotSpot == null)
            hotSpot = new Point();
        Dimension prefDimension = Toolkit.getDefaultToolkit().getBestCursorSize(hotSpot.x, hotSpot.y);
        if (hotSpot.x > prefDimension.width - 1)
            hotSpot.x = prefDimension.width - 1;
        else if (hotSpot.x < 0)
            hotSpot.x = 0;
        if (hotSpot.y > prefDimension.height - 1)
            hotSpot.y = prefDimension.height - 1;
        else if (hotSpot.y < 0)
            hotSpot.y = 0;
        return Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, hotSpot, name);
    }
}

Related

  1. absoluteDifferenceImage(ImageIcon icon1, ImageIcon icon2, double scale)
  2. componentToImageIcon(Component c, String description, boolean paintBorder)
  3. convert(ImageIcon icon)
  4. createBase64StringFromImage(ImageIcon image)
  5. createColorImageIcon(int w, int h, int c)
  6. createCursor(ImageIcon icon, Point hotspot)
  7. createDisabledImage(final ImageIcon imageIcon)
  8. createEmptyImageIcon(final int width, final int height)
  9. createFileImageIcon(final String path)