在下面的代码中,我有一个 ToolBar,并向其中添加了各种大小的按钮。我希望按钮是方形的并且大小都一样。所以基本上从所有按钮中找到最长的宽度或高度,并将所有其他按钮的宽度和高度设置为这个大小。但是,按钮可以改变大小,所以我认为我需要一个绑定。我不太明白 - 有人知道怎么做吗?
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class ToolBarButtonTest extends Application {
@Override
public void start(Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
Scene scene = new Scene(borderPane, 500, 500);
ToolBar toolBar = new ToolBar();
Button button1 = new Button("s");
Button button2 = new Button("ss");
Button button3 = new Button("sss");
toolBar.getItems().addAll(button1, button2, button3);
borderPane.setTop(toolBar);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
谢谢,尼克。