GroovyからJavaFX2.0を使ってみる、その2
Accordionなるコントロールがあったので試しに使ってみた
Accordionの要素であるTitlePaneはNode型ならなんでも入るという素晴らしさ(`・ω・´)
- 実行結果
- ソース
import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.Group; import javafx.scene.layout.*; import javafx.scene.control.*; import javafx.builders.*; class GroovyTest1 { static void main(args){ Application.launch(TestWindow, args) } } class TestWindow extends Application{ void start(Stage stage){ // タイトル、コンテンツ共に普通にコントロールとして機能します // タイトルをラベル、コンテンツをボタン def titledPane1 = new TitledPane(new Label("ラベルのタイトル"), new Button("ボタン")); // タイトルをボタン、コンテンツをラベル def titledPane2 = new TitledPane(new Button("ボタンのタイトル"), new Label("ラベル")); // タイトルをチェックボックス、コンテンツをテキストボックス def titledPane3 = new TitledPane(new CheckBox("チェックボックスのタイトル"), new TextBox("テキストボックス")); // VBoxとHBoxを使ってみる def vbox = new VBox(spacing:4) def hbox = new HBox(spacing:4) hbox.children.addAll( new Button("ボタン"), new Label("ラベル"), new TextBox("テキストボックス"), ) vbox.children.addAll( new Label("ラベル"), new Button("ボタン"), new TextBox("テキストボックス"), new CheckBox("チェックボックス"), hbox, ) def titledPane4 = new TitledPane(new Label("コンテンツにVBox"), vbox); def accordion = new Accordion() accordion.panes.addAll( titledPane1, titledPane2, titledPane3, titledPane4, ) stage.with{ title = "JavaFX Controls" scene = new Scene( accordion, 300, 300 ) visible = true } } }