How to change the cursor type

Posted by Jessy on Stack Overflow See other posts from Stack Overflow or by Jessy
Published on 2010-03-28T22:56:11Z Indexed on 2010/03/28 23:03 UTC
Read the original article Hit count: 355

Filed under:
|
|
|

This question is related to the previous post. http://stackoverflow.com/questions/2532936/how-to-save-file-and-read

alt text

How can I change the cursor to "Hand" only when the mouse pointed on grid which is not Null (contained images)?

So far the cursor turn to "Hand" all over the grids (null or not null).

public GUI() {
....
  JPanel pDraw = new JPanel();
  ....
  for(Component component: pDraw.getComponents()){
     JLabel lbl = (JLabel)component;

     //add mouse listener to grid box which contained image
     if (lbl.getIcon() != null)
        lbl.addMouseListener(this);
  }

  public void mouseEntered(MouseEvent e) {
     Cursor cursor = Cursor.getDefaultCursor();
     //change cursor appearance to HAND_CURSOR when the mouse pointed on images
     cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 
     setCursor(cursor);
  }

© Stack Overflow or respective owner

Related posts about java

Related posts about cursor