![](/img/trans.png)
[英]JavaFX Hbox of buttons won't fill space of bottom container in BorderPane
[英]JavaFX BorderPane throwing errors when trying to assign HBox to the bottom
我試圖將按鈕放在BorderPane的底部,但我不斷收到錯誤消息,以前我一直在使用它,但是現在收到錯誤消息“ Application start method中的異常”。
package assign3;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Question2 extends Application
{
@Override
public void start( Stage obPrimeStage ) throws Exception
{
Button btRed = new Button("Red");
Button btGreen = new Button("Green");
Button btBlue = new Button("Blue");
Button btOrange = new Button("Orange");
Button btStart = new Button("Start");
BorderPane obBorder = new BorderPane();
HBox obPane = new HBox();
obPane.getChildren().add(btRed);
obPane.getChildren().add(btGreen);
obPane.getChildren().add(btBlue);
obPane.getChildren().add(btOrange);
obPane.getChildren().add(btStart);
obBorder.setBottom(obPane);
Scene obScene = new Scene(obPane, 400, 400);
obPrimeStage.setTitle("Question 2");
obPrimeStage.setScene(obScene);
obPrimeStage.show();
btRed.setOnAction((ActionEvent e) ->
{
obPane.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
});
btGreen.setOnAction((ActionEvent e) ->
{
obPane.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY)));
});
btBlue.setOnAction((ActionEvent e) ->
{
obPane.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
});
}
public static void main( String[] args )
{
Application.launch(args);
}
}
我覺得這與obBorder.setBottom(obPane)有關,但不確定。 我們的講師掩蓋了所有這些,即使看了javadoc,我也很難理解。
任何幫助將不勝感激。
您不能將節點添加到另一個窗格, 並使其成為場景的根。 (閱讀堆棧跟蹤 :它可以告訴您確切的錯誤信息。)
我想你是說
Scene obScene = new Scene(obBorder, 400, 400);
代替
Scene obScene = new Scene(obPane, 400, 400);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.