Example usage for java.awt Cursor HAND_CURSOR

List of usage examples for java.awt Cursor HAND_CURSOR

Introduction

In this page you can find the example usage for java.awt Cursor HAND_CURSOR.

Prototype

int HAND_CURSOR

To view the source code for java.awt Cursor HAND_CURSOR.

Click Source Link

Document

The hand cursor type.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    aWindow.setVisible(true);/*  w ww. j a  va 2s .c o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Main mainForm = new Main();
            mainForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            mainForm.setSize(250, 250);//  w  w w.  jav  a 2s  . co  m

            Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
            mainForm.setCursor(cursor);

            mainForm.pack();
            mainForm.setVisible(true);
        }
    });
}

From source file:Main.java

public static final void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane textPane = new JTextPane();
    textPane.addMouseMotionListener(new MouseAdapter() {
        public void mouseMoved(MouseEvent e) {
            AttributeSet style = getAttributes(e);
            if (style != null && StyleConstants.getIcon(style) != null) {
                textPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else {
                textPane.setCursor(Cursor.getDefaultCursor());
            }//from ww w.  ja  v a  2 s  .  co  m
        }
    });
    frame.add(new JScrollPane(textPane));

    StyledDocument doc = (StyledDocument) textPane.getDocument();

    SimpleAttributeSet style = new SimpleAttributeSet();
    StyleConstants.setIcon(style, createImage());

    doc.insertString(doc.getLength(), "this is a test", null);
    doc.insertString(doc.getLength(), "test", style);
    doc.insertString(doc.getLength(), "this is a test\n", null);
    doc.insertString(doc.getLength(), "another image", style);

    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

public static void main() {
    Component comp = new Button("OK");

    Cursor cursor = comp.getCursor();

    comp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    JFrame frame = new JFrame();
    frame.add(comp);/*w  w  w. ja  va  2 s  .co m*/
    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static Cursor getHandCursor() {
    if (mHandCursor == null) {
        mHandCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
    }//from  w w  w . j ava2 s.  c  om

    return mHandCursor;
}

From source file:Main.java

/**
 * Configures a label as if it was an hyperlink.
 * /*from   w  w  w  .j a  va 2 s  .c om*/
 * @param label
 *            the label to configure.
 */
public static void configureLabelAsHyperlink(JLabel label) {
    if (label == null) {
        return;
    }

    StringBuffer html = new StringBuffer();
    html.append("<html><font color=\"blue\"><u>");
    html.append(label.getText());
    html.append("</u></font></html>");

    label.setText(html.toString());
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

From source file:Main.java

/**
 * Create a HTML hyperlink in JLabel component
 *
 * @param label//from   www  .ja v a 2s  .c o  m
 * @param url
 * @param text
 */
public static void createHyperLink(JLabel label, final String url, String text) {
    label.setToolTipText(url);
    label.setText("<html><a href=\"\">" + text + "</a></html>");
    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(url));
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            } catch (URISyntaxException ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}

From source file:Main.java

/**
 * Configures a button as if it was an hyperlink.
 * /*ww  w .  j  a v a 2s.c  om*/
 * @param button
 *            the button to configure.
 */
public static void configureButtonAsHyperlink(JButton button) {
    if (button == null) {
        return;
    }

    StringBuffer html = new StringBuffer();
    html.append("<html><font color=\"blue\"><u>");
    html.append(button.getText());
    html.append("</u></font></html>");

    button.setText(html.toString());
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    button.setFocusPainted(false);
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
}

From source file:Main.java

/**
 * Adds a hand cursor to the component, as well as a click listener that
 * triggers a browse action to the given url.
 *//*  w  ww  .ja v a 2  s  . c  om*/
public static void addBrowseBehavior(final Component cmp, final String url) {
    if (url == null)
        return;
    cmp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    cmp.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            JFrame frame = getJFrame(cmp);
            browse(url, frame);
        }
    });
}

From source file:Main.java

/**
 * Adds a hand cursor to the component, as well as a click listener that
 * triggers a browse action to the given url.
 *//*  www .j  a va 2s . c  om*/
public static void addBrowseBehavior(final Component cmp, final String url) {
    if (url == null) {
        return;
    }
    cmp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    cmp.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            JFrame frame = getJFrame(cmp);
            browse(url, frame);
        }
    });
}