2013-03-10 330 views
6

如何实现整个SplitPane的比例调整大小?JavaFX - SplitPane,调整大小和比例

public class JfxSplitPaneTest extends Application { 
    @Override 
    public void start(Stage stage) throws Exception { 
     SplitPane split = new SplitPane(); 
     StackPane child1 = new StackPane(); 
     child1.setStyle("-fx-background-color: #0000AA;"); 
     StackPane child2 = new StackPane(); 
     child2.setStyle("-fx-background-color: #00AA00;"); 
     StackPane child3 = new StackPane(); 
     child3.setStyle("-fx-background-color: #AA0000;"); 
     split.getItems().addAll(child1, child2, child3); 
     //split.setDividerPositions(0.1f, 0.6f, 0.9f) 
     stage.setScene(new Scene(split, 400, 300)); 
     stage.show(); 
    } 
    public static void main(String[] args) { 
     launch(args); 
    } 
} 

启动程序:

enter image description here

设置分隔怎么我喜欢他们:

enter image description here

使窗口宽度非常小(我继续,并使其更小,没有图片):

enter image description here

调整回头并观察分隔符既不是我如何设置它们,也不是程序启动时的样子。

enter image description here

这样做可以更接近我所期望的:

child1.setMinWidth(Region.USE_PREF_SIZE) 
    child1.setPrefWidth(100) 
    child2.setMinWidth(Region.USE_PREF_SIZE) 
    child2.setPrefWidth(200) 
    child3.setMinWidth(Region.USE_PREF_SIZE) 
    child3.setPrefWidth(300) 
除了分频器进行initally在错误的位置(直到我调整SplitPane,1px的就够了)和收缩窗口时

宽度,分隔符是内部组件。

我该如何做这项工作?

回答

1

试图改变监听器添加到stage.widthProperty()stage.heightProperty()。并称之为:

split.setDividerPositions(0.1f, 0.6f, 0.9f)