如何在scala中创建一个包含RadioButtons的新ButtonGroup?
我在使用 Scala 编程语言创建包含单选按钮的 ButtonGroup 时遇到问题。我使用的代码如下:
val buttongroup = new ButtonGroup {
buttons += new RadioButton("One")
buttons += new RadioButton("Two")
}
我的用于显示按钮组的代码位于 BorderPanel 内:
layout += new BoxPanel(Orientation.Vertical) {
buttongroup
} -> BorderPanel.Position.West
但是,没有显示任何内容...我已经查阅了 API,但不确定出了什么问题!
I am having trouble creating a ButtonGroup containing radio buttons in the Scala Programming Language. The code I am using is as following:
val buttongroup = new ButtonGroup {
buttons += new RadioButton("One")
buttons += new RadioButton("Two")
}
and my code for displaying the button group is within a BorderPanel:
layout += new BoxPanel(Orientation.Vertical) {
buttongroup
} -> BorderPanel.Position.West
However, nothing displays... I've consulted the API and I'm not sure what is wrong!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将包含按钮的列表添加到面板,而不是按钮组本身,例如:
另请参阅 此示例位于 scala swing 包本身中。
You should add a list containing the buttons to the panel, not the buttongroup itself, e.g.:
See also this example in the scala swing package itself.
虽然按钮组使按钮互斥,但您仍然需要向面板添加单独的按钮。您可以使用
ButtonGroup.buttons
获取按钮列表:如果您希望在创建工具栏时选择第一个按钮,您可以添加:
buttongroup.select(buttongroup.buttons .head)
While the button group makes the buttons mututaly exclusive, you still need to add individual buttons to the panel. You can use
ButtonGroup.buttons
to obtain the list of the buttons:If you want the first button to be selected when the toolbar is created, you can add:
buttongroup.select(buttongroup.buttons.head)