Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new ButtonGroup in scala containing RadioButtons?

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!!

like image 950
MRN Avatar asked Dec 06 '25 06:12

MRN


1 Answers

You should add a list containing the buttons to the panel, not the buttongroup itself, e.g.:


val radios = List(new RadioButton("One"), new RadioButton("two"))
layout += new BoxPanel(Orientation.Vertical) {
  contents ++= radios         
}

See also this example in the scala swing package itself.

like image 92
Arjan Blokzijl Avatar answered Dec 08 '25 18:12

Arjan Blokzijl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!