javafx.scene.control.RadioButton
RadioButtonは、複数項目の中から「1つだけ」を選択する場合に使用するコントロールです。
- 1 :
 2 :
 3 :
 4 :
 5 :
 6 :
 7 :
 8 :
 9 :
 10 :
 11 :
 12 :
 13 :
 14 :
 15 :
 16 :
 17 :
 18 :
 19 :
 20 :
 21 :
 22 :
 23 :
 24 :
 25 :
 26 :
 27 :
 28 :
 29 :
 30 :
 31 :
 32 :
 33 :
 34 :
 35 :
 36 :
 37 :
 38 :
 39 :
 40 :
 41 :
 42 :
 43 :
 44 :
 45 :
 46 :
 47 :
 48 :
 49 :
 50 :
 51 :
 52 :
 53 :
 54 :
 55 :
 56 :
 57 :
 58 :
- 
import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class JavaFX_RadioButton extends Application { public static void main(String... args){ Application.launch(args); } @Override public void start(Stage stage) throws Exception { // ステージ調整 stage . setTitle( "RaidoButton" ); stage . setWidth( 500 ); stage . setHeight( 300 ); // グループの作成 ToggleGroup group = new ToggleGroup(); // ラジオボタンの作成 RadioButton radioButton1 = new RadioButton( "上" ); RadioButton radioButton2 = new RadioButton( "中" ); RadioButton radioButton3 = new RadioButton( "下" ); // ラジオボタンをグルーピングする。 radioButton1 . setToggleGroup( group ); radioButton2 . setToggleGroup( group ); radioButton3 . setToggleGroup( group ); // レイアウト VBox vbox = new VBox(); vbox . setAlignment( Pos . CENTER ); vbox . setPadding( new Insets( 20 , 20 , 20 , 20 ) ); vbox . setSpacing( 20.0 ); vbox . getChildren() . addAll( radioButton1 , radioButton2 , radioButton3 ); // sceanの配置 Scene scene = new Scene( vbox ); stage . setTitle( "RadioButton" ); stage . setWidth( 300 ); stage . setHeight( 200 ); stage . setScene( scene ); stage . show(); } }
【 サンプルソース No.1 RadioButton  】
実行結果
 
	RadioButtonのグルーピングは下記の部分で設定しています。
- 28 :
 29 :
- 
		// グループの作成 ToggleGroup group = new ToggleGroup(); 
- 36 :
 37 :
 38 :
 39 :
- 
		// ラジオボタンをグルーピングする。 radioButton1 . setToggleGroup( group ); radioButton2 . setToggleGroup( group ); radioButton3 . setToggleGroup( group ); 
選択されたRadioButtonを取得する
RadioButtonは、グループ化された複数の中から「1つだけ」を選択する場合に使用するコントロールです。選択中のRaidoButtonは、グループ化するためのToggleGroupから取得できます。
<< 選択されたRadioButtonを取得にはこちらへ >>
