[英]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.