JavaFx 应用程序中的 BorderPane 不显示底部区域节点,除非在使用 Button 事件切换场景时窗口最大化。如果场景一个接一个地切换,它的安排就完美了。我的代码中有错误还是这是默认行为?谢谢。系统:Windows XP Java 版本:7
我的SSCE:
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class Main extends Application {
@Override
public void start(final Stage stage) {
try {
///// 2nd scene
BorderPane root2 = new BorderPane();
root2.setPrefSize(stage.getWidth(),stage.getHeight());
HBox buttons2=new HBox(50);
buttons2.getChildren().addAll(new Button("Button1"),new Button("Button2"));
buttons2.setAlignment(Pos.BOTTOM_CENTER);
root2.setBottom(buttons2);
final Scene scene2 = new Scene(root2,stage.getWidth(),stage.getHeight());
///// 1st scene
VBox buttons1=new VBox();
buttons1.setPrefSize(stage.getWidth(),stage.getHeight());
Button nextSceneBtn=new Button("NEXT");
buttons1.getChildren().add(nextSceneBtn);
buttons1.setAlignment(Pos.CENTER);
Scene scene1=new Scene(buttons1,stage.getWidth(),stage.getHeight());
////action event
nextSceneBtn.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event) {
stage.setScene(scene2);
}
});
///stage
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
stage.setX(0);
stage.setY(0);
stage.setWidth(bounds.getWidth());
stage.setHeight(bounds.getHeight());
stage.setScene(scene1); //if it's #setScene(scene2) at the beginning, it's ok
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}