2014-01-28 123 views
1

我有一個佈局,其中有一個垂直分割窗格,它將兩個組件分開。在我想要增長的分割面右側的組件(它是一個圖像),但是分割窗格左側的組件需要保持在與分割器完全相同的位置,當窗口位於完全相同的位置時被放大。防止SplitPane在javafx中調整大小

我試圖將左側AnchorPane包裝在一個Vbox中,除非窗口被調整大小,左側的所有組件都會被移動,否則它似乎可以工作。這也發生在我將它包裹在HBox中時。

我想不出解決這個問題的最佳方法。我正在使用場景構建器,而且我對Javafx還很陌生。誰能幫忙?

謝謝!

+0

你設置AnchorPane的MaxWidth和MaxHeight? – Math

+0

@Math是,兩者都設置爲USE_COMPUTED_SIZE – John

+0

嘗試將MaxWidth和MaxHeight設置爲定義的像素值,以確保它不會超出此範圍。 –

回答

4

調用一個不能與成長相同的固定值將防止用戶更改分隔條位置的組件上setMinWidthsetMaxWidth

因此,例如,讓我們說,你想的100爲您的左部件的最大尺寸,代碼可能是:

SplitPane pane = new SplitPane(); 

double leftComponentSize = 100.0; 
VBox leftComponent = new VBox(); 
// Set the min and max with to a fixed size 
leftComponent.setMinWidth(leftComponentSize); 
leftComponent.setMaxWidth(leftComponentSize); 
... 
pane.getItems().addAll(leftComponent, rightComponent); 
// Initialize the divider positions to allocate the expected size 
// to the left component according to the size of the window 
pane.setDividerPositions(leftComponentSize/stage.getScene().getWidth());