创建栈面板,将在其上放置两个按钮,并用样式属性设置按钮和栈面板的外观样式。
package yuan; //栈面板的应用
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane; //加载栈面板类
public class App14_3 extends Application{
Button bt =new Button(“确定”);
@Override
public void start(Stage primaryStage) {
// TODO Auto-generated method stub
StackPane sPane = new StackPane(); //创建栈面板对象
bt.setStyle("-fx-border-color:blue");//设置按钮的边框颜色为蓝色
Button bt1 = new Button("我也是按钮");
bt1.setPrefSize(80, 50); //设置按钮的优先大小,即自定义按钮的大小
bt.setStyle("-fx-border-color:green"); //设置bt1按钮的边框颜色为绿色
bt1.setRotate(-45); //将bt1按钮按逆时针旋转45度
sPane.getChildren().addAll(bt1,bt); //将按钮加入栈面板中
sPane.setRotate(45); //设置将栈面板顺时针旋转45度
sPane.setStyle("-fx-border-color:red;-fx-background-color:lightgray");
Scene scene = new Scene(sPane,180,100);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Application.launch(args); //启动独立的JavaFx程序
}