2017-04-04 46 views
0

目前我gridpane撑集中在X轴上,而调整窗口的大小,我怎样才能得到它留在Y轴为中心呢?GridPane留中心,而调整窗口的大小

我有这样的一个TabPane标签:

GridPane grid = new GridPane(); 
    grid.setPadding(new Insets(20, 0, 0, 0)); 
    grid.setAlignment(Pos.CENTER); 
    grid.setHgap(20); 
    grid.setVgap(20); 

    this.setContent(grid); 
+0

您必须添加某种代码这样我们就能看到你在做什么以及你在做什么。 – Sedrick

+0

@SedrickJefferson如果你想有一个明确的答案,你应该补充的完整代码视图我已经添加了代码 –

+0

。 – Sedrick

回答

0

这里的关键是VBox.setVgrow(tabPane, Priority.ALWAYS);

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.MenuBar; 
import javafx.scene.control.TabPane; 
import javafx.scene.layout.Priority; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

/** 
* 
* @author blj0011 
*/ 
public class JavaFXApplication65 extends Application 
{ 

    @Override 
    public void start(Stage primaryStage) 
    { 
     VBox root = new VBox(); 
     MenuBar mb = new MenuBar(); 

     TabPane tabPane = new TabPane(); 
     root.getChildren().addAll(mb, tabPane); 


     //StackPane stackPane = new StackPane(); 
     CreateProfilePane cp = new CreateProfilePane(); 
     tabPane.getTabs().add(cp); 
     VBox.setVgrow(tabPane, Priority.ALWAYS); 



     Scene scene = new Scene(root, 300, 250); 

     primaryStage.setTitle("Hello World!"); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) 
    { 
     launch(args); 
    } 

} 

enter image description here

enter image description here

+0

我StackPane是一个选项卡,以便电网仍然不集中当窗口被调整大小时。有没有办法解决它? @SedrickJefferson –

+0

请参见[这](https://gyazo.com/642302a0d1ea63b779f8c638708393d3)截图中,StackPane充满绿色。 –

+0

看起来像你需要vgow =始终在stackpane; – Sedrick