Created
January 21, 2010 10:30
-
-
Save bluepapa32/282713 to your computer and use it in GitHub Desktop.
How to use RadioButton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.scene.*; | |
import javafx.scene.control.*; | |
import javafx.scene.layout.*; | |
import javafx.stage.*; | |
import javafx.util.Sequences.*; | |
class Item { | |
public var text: String; | |
public var value: Object; | |
} | |
class RadioButtonView extends CustomNode { | |
def group = ToggleGroup {} | |
var values: Object[]; | |
public var items: Item[] on replace { | |
for (item in items) { | |
RadioButton { text: item.text, toggleGroup: group } | |
insert item.value into values; | |
} | |
}; | |
public var selectedValue: Object on replace { | |
if (selectedValue != null) { | |
group.buttons[indexOf(values, selectedValue)].selected = true; | |
} | |
} | |
var selectedButton = bind group.selectedButton on replace { | |
if (selectedButton != null) { | |
selectedValue = items[indexOf(group.buttons, selectedButton)].value; | |
} | |
} | |
override function create(): Node { | |
HBox { spacing: 5, content: group.buttons } | |
} | |
} | |
var value: Object on replace { | |
println(value); | |
} | |
Stage { | |
scene: Scene { | |
content: RadioButtonView { | |
items: [ | |
Item { text: "FOO", value: 1 } | |
Item { text: "BAR", value: 2 } | |
Item { text: "HOGE", value: 3 } | |
] | |
selectedValue: bind value with inverse | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment