我有这个简单的对话框,将在应用程序关闭时调用。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class test extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage)
{
// Image
Image image = new Image("http://docs.oracle.com/javafx/"
+ "javafx/images/javafx-documentation.png");
ImageView imageView = new ImageView();
imageView.setImage(image);
// Text
Text t = new Text();
t.setText("This is a text sample");
// Buttons
Button btnYes = new Button("Yes");
Button btnNo = new Button("No");
// Buttons layout
HBox hbox = new HBox(8); // spacing = 8
hbox.setStyle("-fx-padding: 15; -fx-font-size: 15pt;");
hbox.getChildren().addAll(btnYes, btnNo);
hbox.setAlignment(Pos.BASELINE_RIGHT);
////////////////////////
BorderPane bp = new BorderPane();
bp.setPadding(new Insets(10, 20, 10, 20));
//Button btnTop = new Button("Top");
bp.setTop(null);
//Button btnLeft = new Button("Left");
bp.setLeft(imageView);
//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, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
}
到目前为止,它看起来像这样:
我想让它看起来像这样:
你能帮我如何改进按钮的视觉布局吗?我不知道如何使这个按钮看起来像示例以及如何设置背景颜色渐变。