无法将帧光标更改为自定义光标

时间:2013-09-06 22:25:54

标签: swing scala

我可以将光标从系统更改为一个,但不能使我创建的那个被显示,我完全不知道我做错了什么,它不会向我抛出任何异常。这是我的代码:

class CustomWin extends MainFrame{

title = "SdC2 Launcher"
cursor = defineCursor
iconImage = defineIcon
visible = true

contents = new BoxPanel(Orientation.Vertical){
  contents += new Label("Label de prueba")
  contents += new Label("Label de prueba")
  val lab = new Label("Label de prueba")
  lab cursor = defineCursor
  contents += lab
}

preferredSize = new Dimension(300,300)
centerOnScreen
pack
open

private val defineCursor = {
  val hotspot = new Point(0, 0)
   //val image = ImageIO.read(new File("images/cursor.png"))
  val image = new ImageIcon("/images/cursor2.gif")
  toolkit.createCustomCursor(image.getImage(), hotspot, "MainCursor")
}

private val defineIcon: Image = new ImageIcon(getClass().getResource("/images/cursor.png")).getImage()
}

1 个答案:

答案 0 :(得分:1)

我怀疑您遇到了初始化顺序问题。也就是说,在您致电cursor = defineCursorlab cursor = defineCursor时,defineCursor仍为null。您应该在构造函数代码中的位置之前初始化val