这个问题与上一篇文章有关。 如何保存文件和读取
替代文字 http://freeimagehosting.net/image.php?dc73c3bb33.jpg
仅当鼠标指向非空网格(包含图像)时,如何将光标更改为“手”?
到目前为止,光标在整个网格(null 或 not null)上都变成了“Hand”。
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);
}