この質問は、以前の投稿に関連しています。 ファイルの保存方法と読み込み方法
代替テキスト http://freeimagehosting.net/image.php?dc73c3bb33.jpg
マウスがNullではないグリッド(含まれる画像)を指している場合にのみ、カーソルを「手」に変更するにはどうすればよいですか?
これまでのところ、カーソルはグリッド全体で「手」に変わります (null または 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);
}