2017-03-24 2 views
1

これは私がGUIを起動したコードです。他の方法を実装する方法を理解することはできません。メインフレームのサイズを手動で変更しようとすると、GUI内のコンテンツが食べられるようになります。フレームを中心にしてサイズを変更したいと思います。javafxのGUIのバックグラウンドを保つのに問題があります

package view; 

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 
import singleton.MainModel; 

public class MainView extends Application { 
    @Override 
    public void start(Stage primaryStage) { 
     // Initialize mainController. 
     MainController mainController = new MainController(); 

     // Add the controller to the singleton. 
     MainModel.getModel().getMainData().setMainController(mainController); 

     // Initialize display components. 
     Group root = new Group(); 
     Scene scene = new Scene(root, 1280, 720); 

     // Add mainController. 
     root.getChildren().addAll(mainController); 

     // Pin the root to scene and display it. 
     primaryStage.setScene(scene); 
     primaryStage.show(); 

     // Properly terminate the application if the user presses the "X" window button. 
     primaryStage.setOnCloseRequest(event -> { 
      mainController.closeApplication(); 
      stop(); 
     }); 

     // Set the title and make the application a fixed size. 
     primaryStage.setTitle("Visual Earth Modelling System"); 
     primaryStage.setResizable(true); 
     primaryStage.sizeToScene(); 



     // Add the stage to the singleton. 
     MainModel.getModel().getMainData().setMainStage(primaryStage); 

     // Go to the first screen. 
     mainController.goToLoginScreen(); 
    } 

    /** 
    * To destroy resources upon application close. Should be called in all instances of a properly closed JavaFX application. 
    */ 
    @Override 
    public void stop() { 
     if (MainModel.getModel().getNetworkData().isHandlerSet()) 
      MainModel.getModel().getNetworkData().closeHandler(); 
    } 

    /** 
    * This method is actually not used in a correctly deployed JavaFX application. Instead, the start method above is called. This main serves as a fallback in case of improper configuration. 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 
} 

enter image description here

答えて

0

StackPaneGroupを交換してください。 StackPaneは、デフォルトで、子の整列を中央に設定します。アライメントが正しいことを確認するには、StackPane.setAlignment(Pos value)で明示的に設定することができます。

StackPane root = new StackPane(); 
root.setAlignment(Pos.CENTER); 
root.getChildren().add(mainController); 
Scene scene = new Scene(root, 1280, 720); 
+0

ありがとう – JJC

関連する問題