java设置鼠标在jpanel时变为手指形状
展开全部
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
/**
* 面板上的光标改变成为手型
* @author hardneedl
*/
final class JPaneCursorDemo extends JFrame{
private static final Dimension SIZE = new Dimension(300,300);
public Dimension getMinimumSize() {return SIZE;}
public Dimension getMaximumSize() {return SIZE;}
public Dimension getPreferredSize() {return SIZE;}
public String getTitle() {return "JPaneCursorDemo";}
private JPanel panel;
JPaneCursorDemo() {
super();
init();
addListeners();
doLay();
}
private void init(){
panel=new JPanel(){
public Border getBorder() {
return BorderFactory.createLineBorder(Color.BLACK,2);
}
};
panel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
private void addListeners(){
}
private void doLay(){
Container container = getContentPane();
container.add(panel);
pack();
setVisible(true);
}
public static void main(String... args) {
System.setProperty("swing.defaultlaf","com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.invokeLater(JPaneCursorDemo::new);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询