2011-07-26 42 views
0

從以前的JavaFX 2.0版本更新到JavaFX 2.0 b36(SDK for Windows(32位)+ Netbeans Plugin)後,SplitPane控件無法再按預期工作。JavaFX 2.0 SplitPane不再按預期工作

  1. 分頻器不能移動
  2. 未如預期
  3. 所包含的雙方的尺寸並不如預期

這裏是一個SplitPane我的示例代碼的分隔條位置。

public class FxTest extends Application { 

    public static void main(String[] args) { 
     Application.launch(FxTest.class, args); 
    } 

    @Override 
    public void start(Stage primaryStage) { 
     primaryStage.setTitle("SplitPane Test"); 

     Group root = new Group(); 
     Scene scene = new Scene(root, 200, 200, Color.WHITE); 

     Button button1 = new Button("Button 1"); 
     Button button2 = new Button("Button 2"); 

     SplitPane splitPane = new SplitPane(); 
     splitPane.setPrefSize(200, 200); 
     splitPane.setOrientation(Orientation.HORIZONTAL); 
     splitPane.setDividerPosition(0, 0.7); 
     splitPane.getItems().addAll(button1, button2); 

     root.getChildren().add(splitPane); 

     primaryStage.setScene(scene); 
     primaryStage.setVisible(true); 
    } 
} 

正如你可以(希望)看到左側明顯小於右側。

另一個有趣的事實是,當你改變方向垂直

splitPane.setOrientation(Orientation.VERTICAL); 

,並嘗試移動分界線,向上或向下,你得到一些控制檯輸出說「這裏」。 看起來像一些測試輸出。

這是什麼問題?

+0

同樣的事情發生在我身上。 – cybermotron

回答

3

要讓SplitPane按預期工作,請向每邊添加布局(例如BorderPane)。添加控件以顯示到每個這些佈局。我認爲這應該在API文檔中更加清楚!

public class FxTest extends Application { 

    public static void main(String[] args) { 
     Application.launch(FxTest.class, args); 
    } 

    @Override 
    public void start(Stage primaryStage) { 
     primaryStage.setTitle("SplitPane Test"); 

     Group root = new Group(); 
     Scene scene = new Scene(root, 200, 200, Color.WHITE); 

     //CREATE THE SPLITPANE 
     SplitPane splitPane = new SplitPane(); 
     splitPane.setPrefSize(200, 200); 
     splitPane.setOrientation(Orientation.HORIZONTAL); 
     splitPane.setDividerPosition(0, 0.7); 

     //ADD LAYOUTS AND ASSIGN CONTAINED CONTROLS 
     Button button1 = new Button("Button 1"); 
     Button button2 = new Button("Button 2"); 

     BorderPane leftPane = new BorderPane(); 
     leftPane.getChildren().add(button1); 

     BorderPane rightPane = new BorderPane(); 
     rightPane.getChildren().add(button2); 

     splitPane.getItems().addAll(leftPane, rightPane); 

     //ADD SPLITPANE TO ROOT 
     root.getChildren().add(splitPane); 

     primaryStage.setScene(scene); 
     primaryStage.setVisible(true); 
    } 
}