Example usage for javax.swing.text JTextComponent setCursor

List of usage examples for javax.swing.text JTextComponent setCursor

Introduction

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

Prototype

public void setCursor(Cursor cursor) 

Source Link

Document

Sets the cursor image to the specified cursor.

Usage

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions.
 *//*from ww w.ja  v  a 2 s.  com*/
protected void addCopyMenu(final JTextComponent component) {
    Preconditions.checkNotNull(component);

    if (!component.isEditable()) {
        component.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    }

    final JPopupMenu contextMenu = new JPopupMenu();
    JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction));
    copy.setText(i18n.getString(I18n.TEXT_COPY_ID));
    contextMenu.add(copy);
    contextMenu.addSeparator();

    JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction));
    selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID));
    contextMenu.add(selectAll);

    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                contextMenu.show(component, e.getX(), e.getY());
            }
        }
    });
}