gpt4 book ai didi

javafx-2 - 如何设置文本对齐方式

转载 作者:行者123 更新时间:2023-12-01 11:44:09 25 4
gpt4 key购买 nike

我有这个带有文本的对话框。

public class DX57DC extends Application
{

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

@Override
public void start(Stage primaryStage) throws URISyntaxException, MalformedURLException
{

// Image
ImageView iv = new ImageView(getClass().getResource("system-help.png").toExternalForm());

// Text
Text t = new Text();
t.setTextAlignment(TextAlignment.LEFT);
t.setText("Do you want to quit?");

HBox thbox = new HBox(8); // spacing = 8
thbox.getChildren().addAll(thbox);
thbox.setAlignment(Pos.CENTER);

// Buttons
Button btnYes = new Button("Yes");
Button btnNo = new Button("No");
btnYes.setStyle("-fx-background-color:\n"
+ " rgba(0,0,0,0.08),\n"
+ " linear-gradient(#9a9a9a, #909090),\n"
+ " linear-gradient(white 0%, #f3f3f3 50%, #ececec 51%, #f2f2f2 100%);\n"
+ " -fx-background-insets: 0 0 -1 0,0,1;\n"
+ " -fx-background-radius: 5,5,4;\n"
+ " -fx-padding: 10 26 10 26;\n"
+ " -fx-text-fill: #242d35;\n"
+ " -fx-font-size: 14px;");

btnNo.setStyle("-fx-background-color:\n"
+ " rgba(0,0,0,0.08),\n"
+ " linear-gradient(#9a9a9a, #909090),\n"
+ " linear-gradient(white 0%, #f3f3f3 50%, #ececec 51%, #f2f2f2 100%);\n"
+ " -fx-background-insets: 0 0 -1 0,0,1;\n"
+ " -fx-background-radius: 5,5,4;\n"
+ " -fx-padding: 10 26 10 26;\n"
+ " -fx-text-fill: #242d35;\n"
+ " -fx-font-size: 14px;");

// Image layout
VBox vbox = new VBox(7);
vbox.getChildren().addAll(iv);
vbox.setAlignment(Pos.CENTER);

// Buttons layout
HBox hbox = new HBox(8); // spacing = 8
//hbox.setStyle("-fx-padding: 10; -fx-font-size: 10pt;");
hbox.getChildren().addAll(btnYes, btnNo);
hbox.setAlignment(Pos.CENTER);

BorderPane bp = new BorderPane();
bp.setStyle("-fx-background-color: linear-gradient(#ffffff,#f3f3f4);\n"
+ " -fx-border-width: 1 1 1 1;\n"
+ " -fx-border-color: #b4b4b4 transparent #b4b4b4 transparent;\n"
+ " -fx-font-size: 1.083333em;\n"
+ " -fx-text-fill: #292929;");

bp.setPadding(new Insets(15, 20, 15, 20));
//Button btnTop = new Button("Top");
bp.setTop(null);
//Button btnLeft = new Button("Left");
bp.setLeft(vbox);
//Button btnCenter = new Button("Center");
bp.setCenter(t);
//Button btnRight = new Button("Right");
bp.setRight(null);
//Button btnBottom = new Button("Bottom");
bp.setBottom(hbox);
Scene scene = new Scene(bp, 500, 160);
primaryStage.setScene(scene);
primaryStage.setTitle("Question Dialog");
primaryStage.show();
}
}

你能告诉我如何将文字靠近图片吗?现在文本位于边框 Pane 的中心。

最佳答案

就像你对 ImageView 所做的一样,将它包装在一个 VBox 中 :)

VBox vbox2 = new VBox();
vbox2.getChildren().addAll(t);
vbox2.setAlignment(Pos.CENTER_LEFT);

然后将它添加到边框的中心:

bp.setCenter(vbox2);

关于javafx-2 - 如何设置文本对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16997701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com