java.awt.Cursor类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中java.awt.Cursor类的一些代码示例,展示了Cursor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor类的具体详情如下:
包路径:java.awt.Cursor
类名称:Cursor

Cursor介绍

[英]A class to encapsulate the bitmap representation of the mouse cursor.
[中]用于封装鼠标光标的位图表示形式的类。

代码示例

代码示例来源:origin: stackoverflow.com

private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
private final Point pp = new Point();
private JLabel image;
  Point cp = e.getPoint();
  Point vp = vport.getViewPosition();
  vp.translate(pp.x-cp.x, pp.y-cp.y);
  image.scrollRectToVisible(new Rectangle(vp, vport.getSize()));
  pp.setLocation(cp);
  image.setCursor(hndCursor);
  pp.setLocation(e.getPoint());
  image.setCursor(defCursor);
  image.repaint();

代码示例来源:origin: hsz/idea-gitignore

@Override
public void mouseMoved(MouseEvent e) {
  Cursor cursor = (e.getPoint().getY() <= DRAG_OFFSET) ?
      Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR) : Cursor.getDefaultCursor();
  panel.setCursor(cursor);
}

代码示例来源:origin: stackoverflow.com

public CButton(String txt) {
  super(txt);
  setForeground(Color.WHITE);
  setFont(getFont().deriveFont(Font.BOLD, 13));
  setContentAreaFilled(false);
  setBorder(null);
  setCursor(new Cursor(Cursor.HAND_CURSOR));
  setBorder(new EmptyBorder(50, 50, 50, 50)); // setting the insets 
  setLayout(new GridBagLayout()); 
  add(usrNameLabel, labCnst);
  add(usrNameFeild, txtCnst);
  comp.setForeground(Color.WHITE);
  comp.setFont(getFont().deriveFont(Font.BOLD, 13));
      JFrame frame = new JFrame("Demo: LogIn Dialogue");
      frame.setSize(new Dimension(500, 300)); 
      MainContainer container = new MainContainer();
      frame.add(new MainContainer());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

代码示例来源:origin: plantuml/plantuml

private void updateLinkColor(final Color newLink) {
  if (link != newLink) {
    link = newLink;
    this.setCursor(link == LINK_NORMAL ? Cursor.getDefaultCursor() : Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    repaint();
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void actionPerformed(ActionEvent e) {
  if ("Start".equals(e.getActionCommand())) {
    frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    frame.setIconImage(onIcon.getImage());
    trayIcon.setImage(onIcon.getImage());
    stopApplication();
    frame.setIconImage(offIcon.getImage());
    trayIcon.setImage(offIcon.getImage());
    frame.setCursor(Cursor.getDefaultCursor());
    browserButton.setEnabled(false);
    startButton.setEnabled(true);

代码示例来源:origin: stackoverflow.com

layeredPane.setPreferredSize( boardSize );
layeredPane.addMouseListener( this );
layeredPane.addMouseMotionListener( this );
getContentPane().add(layeredPane);
chessBoard.setLayout( new GridLayout(8, 8) );
chessBoard.setPreferredSize( boardSize );
chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);
layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
    square.setBackground( (i + j) % 2 == 0 ? Color.red : Color.white );
    chessBoard.add( square );
Component c =  chessBoard.findComponentAt(e.getX(), e.getY());
Point parentLocation = c.getParent().getLocation();
xAdjustment = parentLocation.x - e.getX();
yAdjustment = parentLocation.y - e.getY();
chessPiece = (JLabel)c;
layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
layeredPane.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE );
frame.setResizable( false );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

if (w instanceof JFrame) {
  final JFrame j = (JFrame) w;
  if (j.getContentPane().getComponents().length > 0) {
    throw new RuntimeException("ProgramCheck: Parent already contains content.");
  j.getContentPane().add(basePanel);
  ((JFrame) w).getGlassPane().setVisible(false);
  ((JWindow) w).setGlassPane(glassPane);
glassPane.setVisible(true);
    @Override
    public void run() {
      parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      disableUserInput(parent);
      slide(true, slideType);
      enableUserInput(parent);
      parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      isSlideInProgress = false;
  basePanel.revalidate();
  if (useLoop) {
    final int max = (slideType == LEFT) || (slideType == RIGHT) ? w : h;

代码示例来源:origin: stackoverflow.com

doc = jta.getStyledDocument();
jsp = new JScrollPane(jta);
jsp.setPreferredSize(new Dimension(height, width));
frm = new JFrame("awesome");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setLayout(new BorderLayout());
frm.add(jsp, BorderLayout.CENTER);
frm.setLocation(100, 100);
frm.pack();
frm.setVisible(true);
jta.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
fnt = ge.getAvailableFontFamilyNames();
mas = jta.getInputAttributes();
jta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
centerPanel.setPreferredSize(new Dimension(300, 200));
centerPanel.setBackground(Color.green);
centerPanel.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR));
frame.getContentPane().add(centerPanel);
northPanel.setBackground(Color.RED);
northPanel.setForeground(Color.BLACK);
northPanel.setPreferredSize(new Dimension(0, 150));
frame.getContentPane().add(northPanel, BorderLayout.NORTH);
frame.getContentPane().add(eastPanel, BorderLayout.EAST);
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

@Override
public void mouseMoved(MouseEvent e) {
 JTable table = (JTable) e.getSource();
 int col = table.columnAtPoint(new Point(e.getX(), e.getY()));
 if (col != 0 && table.getCursor().getType() == Cursor.HAND_CURSOR) {
  table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 }
 if (col == 0 && table.getCursor().getType() == Cursor.DEFAULT_CURSOR) {
  table.setCursor(new Cursor(Cursor.HAND_CURSOR));
 }
}

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.getContentPane().setPreferredSize(new Dimension(700, 500) );
panel.setPreferredSize(new Dimension(300, 200));
panel.setBackground(Color.green);
panel.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
groupLayout.setHorizontalGroup(
     .addContainerGap(99, Short.MAX_VALUE))
);
frame.getContentPane().setLayout(groupLayout);
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);

代码示例来源:origin: stackoverflow.com

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ExampleClass{    

  public static void main(String args[]){

    JFrame exampleFrame = new JFrame("Test");          
    exampleFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    exampleFrame.setLayout(new FlowLayout());
    exampleFrame.setSize(300, 300);

    JPanel redPanel = new JPanel();
    redPanel.setBackground(Color.RED);
    redPanel.setPreferredSize(new Dimension(150, 300));
    redPanel.setCursor(new Cursor(Cursor.HAND_CURSOR)); // This one line changes the cursor.

    exampleFrame.add(redPanel);
    exampleFrame.setVisible(true);            
  }
}

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JPanel another = new JPanel();
JPanel emptyPanel = new JPanel();
emptyPanel.setPreferredSize(new Dimension(700, 50));
frame.setSize(700, 500); 
panel.setMaximumSize(new Dimension(300, 200));
panel.setMinimumSize(new Dimension(300, 200));
panel.setPreferredSize(new Dimension(300, 200));
panel.setBackground(Color.green);
panel.setCursor(new Cursor(java.awt.Cursor.HAND_CURSOR));
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
another.add(emptyPanel, BorderLayout.NORTH);
another.add(panel, BorderLayout.CENTER);         
frame.add(another);
frame.setVisible(true);
frame.setLocationRelativeTo(null);

代码示例来源:origin: stackoverflow.com

this.setPreferredSize(new Dimension(640, 480));
JFrame f = new JFrame("CursorTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

import java.awt.Cursor;
import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class sample20 {

  public static void main(String args[]) {

    JPanel wnd = new JPanel(new FlowLayout(FlowLayout.LEFT));

    JCheckBox checkbox = new JCheckBox("label");
    checkbox.setCursor(new Cursor(Cursor.HAND_CURSOR)); // this is what you need
    wnd.add(checkbox);

    JFrame frame = new JFrame();
    frame.setSize(500, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(wnd);

    frame.setVisible(true);
  }
}

代码示例来源:origin: stackoverflow.com

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(dragLabel);
pack();
setVisible(true);
  dragTrigger.startDrag(new Cursor(Cursor.HAND_CURSOR), new StringSelection(label.getText()));
};

代码示例来源:origin: stackoverflow.com

this.setSize(300, 100);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setLocationRelativeTo(null);
  contact.setCursor(new Cursor(Cursor.HAND_CURSOR));
  website.setCursor(new Cursor(Cursor.HAND_CURSOR));
pan.add(contact);
pan.add(website);
  this.setContentPane(pan);
  this.setVisible(true);
  sendMail(contact);
  goWebsite(website);
  website.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {

代码示例来源:origin: bobbylight/RSyntaxTextArea

if ((e.getModifiersEx()&linkScanningMask)==linkScanningMask) {
    int x = e.getX();
    int y = e.getY();
    if (x<=insets.left || y<insets.top) {
      if (isScanningForLinks) {
      repaint();
    c2 = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
      c2 = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
        repaint();
      c2 = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
      hoveredOverLinkOffset = -1;
      linkGeneratorResult = null;
    c2 = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
    hoveredOverLinkOffset = -1;
    linkGeneratorResult = null;

代码示例来源:origin: stackoverflow.com

contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
contentPane.add(label);
contentPane.add(label);
if (isBrowsingSupported()) {
  makeLinkable(label, new LinkMouseListener());
assert ml != null;
c.setText(htmlIfy(linkIfy(c.getText())));
c.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
c.addMouseListener(ml);

代码示例来源:origin: stackoverflow.com

this.addMouseListener(this);
this.addFocusListener(this);
this.addActionListener(this);
setToolTipText(target.toString());
setForeground(standardColor);
setBorder(standardBorder);
setCursor( new Cursor(Cursor.HAND_CURSOR) );
p.add(linkLabelFile);
p.add(linkLabelWeb);
labelConstrain.add( linkLabelConstrain, BorderLayout.EAST );
p.add(labelConstrain);

相关文章