JComboBox 类采用类型参数
我想在侦听器中获取 JComboBox 实例的值:
object NoteListener extends ActionListener {
def actionPerformed(e:ActionEvent):Unit = {
println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
}
}
我收到此错误:
[error] .../test.scala:30: class JComboBox takes type parameters
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
当我尝试传递任何参数时:
[error] .../test.scala:30: ']' expected but '(' found.
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox(Array)].getValue)
这是一个错误,还是我的无知?
I want to get value of instance of JComboBox in my listener:
object NoteListener extends ActionListener {
def actionPerformed(e:ActionEvent):Unit = {
println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
}
}
And I get this error:
[error] .../test.scala:30: class JComboBox takes type parameters
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
when I try to pass any parameter:
[error] .../test.scala:30: ']' expected but '(' found.
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox(Array)].getValue)
Is it a bug, or my ignorance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的类型参数不正确:
应该
注意[Array]。这就是在 Scala 中指定类型参数的方式。
Your type parameters are incorrect:
should be
Note the [Array]. This is how you specify type parameters in Scala.
不确定,但这应该给你 JComboBox 的实例
Not sure but this should give you instance of JComboBox