Fra*_*sco 1 css layout javafx fxml scenebuilder
我有这个:
一个带左节点的边框窗格(绿色箭头),里面有按钮(橙色箭头)。
我不能做的是找到一种方法来根据窗口的大小更改 Vbox(绿色段)的尺寸,然后更改按钮(橙色段)的尺寸。(当用户播放窗口大小时)
我更喜欢找到一种方法将参数设置到我的 css 文件中,或者作为最后的手段在我的 fxml 中。
.css 文件:
.left-borderPane{ /*this is style class for Vbox */
/*something so similar: */
-fx-min-width:30% ;
-fx-max-width:30% ;
}
.icon-settings{/*this is style class for buttons*/
-fx-shape:"M72.5,65.9 M90,50c0,8.6-2.5,16.9-7.3,24.1c-0.4,0.6-1,0.9-1.7,0.9c-0.4,0-0.8-0.1-1.1-0.3c-0.9-0.6-1.2-1.8-0.6-2.50zM69.6,50c0,3.2-0.6,6.2-1.8,9.1c-0.3,0.8-1.1,1.2-1.8,1.2c-0.2,0-0.5,0-0.8-0.1c-1-0.4c0.6-0.6,1.4-0.7,2.2-0.4C57.5,14.5,58,15.2,58,16z M35,37H14v26h21V37z M54,20.8l-15,15v28.3l15,15V20.8z";
/*something so similar: */
-fx-min-width:80% ;
-fx-max-width:80% ;
}
Run Code Online (Sandbox Code Playgroud)
不像在网络,即HTML + CSS,JavaFX的+ CSS也不要做定位,并从CSS大小。您必须将左侧面板的大小绑定到窗口的大小(最有可能通过一个简单的计算)以及将按钮的大小绑定到面板的大小(再次通过一个简单的计算)。下面的代码演示了原理:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class BoundSizes extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane borderPane = new BorderPane();
VBox vbox = new VBox();
Button b = new Button("THE BUTTON");
vbox.getChildren().add(b);
borderPane.setLeft(vbox);
// the VBox stays e.g. 1/3 of the window width
vbox.prefWidthProperty().bind(Bindings.divide(primaryStage.widthProperty(), 3.0));
// painting it to be obvious
vbox.setStyle("-fx-background-color: black");
// the button stays e.g. at half the width of the VBox
b.prefWidthProperty().bind(Bindings.divide(vbox.widthProperty(), 2.0));
Scene scene = new Scene(borderPane, 300, 275);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String arg[]) {
launch(arg);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8460 次 |
| 最近记录: |