2016-07-18 20 views
1

ダイアログのボタンの下にテキストなどの情報を表示する方法があるのでしょうか?私は多くの場所を見てきましたが、ボタンを整列させることさえ(このpostから)乱雑です。ダイアログのボタンの下にテキストを追加します

これは私が今持っているものです。私はちょうど2つのボタンの下に "私の選択肢を設定..."テキストが欲しいです。

Dialog simple

私は私はチャンスがないと、私は(のような「getButtonBar()」またはそのような何か)好きな方法を表示助けることができるドキュメントの機能を探しました。また、新しいButtonBarを作成することは、私が達成したいことのために少し複雑に思えます。

また、ダイアログのように見えるステージを作成しようとしましたが、Dialogと同じように「はい/いいえ」をクリックして結果を受け取る必要がありました。

私が望むことを達成する方法はありますか?それとも自分で完全に構築しなければならないのですか?ありがとう!ここでSSCCEだ

DialogPane pane = new DialogPane() { 
    @Override 
    public Node createButtonBar() { 
     VBox vbox = new VBox(5); 
     vbox.setAlignment(Pos.BOTTOM_RIGHT); 
     vbox.setPadding(new Insets(5)); 
     vbox.getChildren().add(super.createButtonBar()); 
     vbox.getChildren().add(new Label("Additional text")); 
     return vbox ; 
    } 
}; 

答えて

5

だけDialogPanecreateButtonBar()メソッドをオーバーライド

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.geometry.Pos; 
import javafx.scene.Node; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ButtonType; 
import javafx.scene.control.CheckBox; 
import javafx.scene.control.Dialog; 
import javafx.scene.control.DialogPane; 
import javafx.scene.control.Label; 
import javafx.scene.layout.StackPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

public class CustomDialogPaneTest extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     Button button = new Button("Show Dialog"); 
     button.setOnAction(e -> { 
      DialogPane pane = new DialogPane() { 
       @Override 
       public Node createButtonBar() { 
        VBox vbox = new VBox(5); 
        vbox.setAlignment(Pos.BOTTOM_RIGHT); 
        vbox.setPadding(new Insets(5)); 
        vbox.getChildren().add(super.createButtonBar()); 
        vbox.getChildren().add(new Label("Additional text")); 
        return vbox ; 
       } 
      }; 

      CheckBox checkBox = new CheckBox("A check box"); 
      pane.setContent(checkBox); 
      pane.setHeaderText("The header"); 
      pane.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); 

      Dialog<ButtonType> dialog = new Dialog<>(); 
      dialog.setDialogPane(pane); 
      dialog.showAndWait().ifPresent(System.out::println); 
     }); 

     StackPane root = new StackPane(button); 
     root.setPadding(new Insets(20)); 
     primaryStage.setScene(new Scene(root)); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

enter image description here

+0

あなたに非常に多くの@Jamesをありがとうございました!私はそれを直接オーバーライドすることを考えなかったし、ダイアログの枠がBorderPaneであることを学びました。もう一度、ありがとう! – Jacks

関連する問題