The TabPane, if setting a prefWidth without setting minWidth, will use prefWidth as minWidth. The result is the dividers cannot be dragged when they are added to a SplitPane.
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class SplitPaneDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// create some tabs.
final TabPane tabPane1 = createTabPane(200, 100);
final TabPane tabPane2 = createTabPane(200, 20);
final TabPane tabPane3 = createTabPane(200, 20);
SplitPane splitPane = new SplitPane();
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.getItems().addAll(tabPane1, tabPane2, tabPane3);
Scene scene = new Scene(splitPane);
splitPane.prefHeightProperty().bind(scene.heightProperty());
splitPane.prefWidthProperty().bind(scene.widthProperty());
stage.setScene(scene);
stage.show();
}
private TabPane createTabPane(double pref, double min) {
final TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Sites");
tab1.setContent(createPane("lightgreen"));
Tab tab2 = new Tab("Favorites");
tab2.setContent(createPane("lightsteelblue"));
Tab tab3 = new Tab("Loves");
tab3.setContent(createPane("pink"));
tabPane.getTabs().addAll(tab1, tab2, tab3);
tabPane.setPrefSize(pref, 200);
// tabPane.setMinSize(min, 200);
return tabPane;
}
// create a pane of a given color to hold tab content.
private Pane createPane(String color) {
final BorderPane pane = new BorderPane();
Text text = new Text();
text.textProperty().bind(pane.widthProperty().asString().concat(" x ").concat(pane.heightProperty().asString()));
pane.setCenter(text);
return pane;
}
}
A possible workaround is to specify the minWidth as well. However, if setResizableWithParent is used, the initial size of the panes will be the minWidth, not the prefWidth. Here is a modified test case from above to demo this issue. Note that the width of the second and third TabPane is 20, not 200.
package jidefx.playground;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class SplitPaneDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// create some tabs.
final TabPane tabPane1 = createTabPane(200, 100);
final TabPane tabPane2 = createTabPane(200, 20);
final TabPane tabPane3 = createTabPane(200, 20);
SplitPane splitPane = new SplitPane();
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.getItems().addAll(tabPane1, tabPane2, tabPane3);
SplitPane.setResizableWithParent(tabPane1, true);
SplitPane.setResizableWithParent(tabPane2, false);
SplitPane.setResizableWithParent(tabPane3, false);
Scene scene = new Scene(splitPane);
splitPane.prefHeightProperty().bind(scene.heightProperty());
splitPane.prefWidthProperty().bind(scene.widthProperty());
stage.setScene(scene);
stage.show();
}
private TabPane createTabPane(double pref, double min) {
final TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Sites");
tab1.setContent(createPane("lightgreen"));
Tab tab2 = new Tab("Favorites");
tab2.setContent(createPane("lightsteelblue"));
Tab tab3 = new Tab("Loves");
tab3.setContent(createPane("pink"));
tabPane.getTabs().addAll(tab1, tab2, tab3);
tabPane.setPrefSize(pref, 200);
tabPane.setMinSize(min, 200);
return tabPane;
}
// create a pane of a given color to hold tab content.
private Pane createPane(String color) {
final BorderPane pane = new BorderPane();
Text text = new Text();
text.textProperty().bind(pane.widthProperty().asString().concat(" x ").concat(pane.heightProperty().asString()));
pane.setCenter(text);
pane.setStyle("-fx-background-color: " + color);
return pane;
}
}
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class SplitPaneDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// create some tabs.
final TabPane tabPane1 = createTabPane(200, 100);
final TabPane tabPane2 = createTabPane(200, 20);
final TabPane tabPane3 = createTabPane(200, 20);
SplitPane splitPane = new SplitPane();
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.getItems().addAll(tabPane1, tabPane2, tabPane3);
Scene scene = new Scene(splitPane);
splitPane.prefHeightProperty().bind(scene.heightProperty());
splitPane.prefWidthProperty().bind(scene.widthProperty());
stage.setScene(scene);
stage.show();
}
private TabPane createTabPane(double pref, double min) {
final TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Sites");
tab1.setContent(createPane("lightgreen"));
Tab tab2 = new Tab("Favorites");
tab2.setContent(createPane("lightsteelblue"));
Tab tab3 = new Tab("Loves");
tab3.setContent(createPane("pink"));
tabPane.getTabs().addAll(tab1, tab2, tab3);
tabPane.setPrefSize(pref, 200);
// tabPane.setMinSize(min, 200);
return tabPane;
}
// create a pane of a given color to hold tab content.
private Pane createPane(String color) {
final BorderPane pane = new BorderPane();
Text text = new Text();
text.textProperty().bind(pane.widthProperty().asString().concat(" x ").concat(pane.heightProperty().asString()));
pane.setCenter(text);
return pane;
}
}
A possible workaround is to specify the minWidth as well. However, if setResizableWithParent is used, the initial size of the panes will be the minWidth, not the prefWidth. Here is a modified test case from above to demo this issue. Note that the width of the second and third TabPane is 20, not 200.
package jidefx.playground;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class SplitPaneDemo extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// create some tabs.
final TabPane tabPane1 = createTabPane(200, 100);
final TabPane tabPane2 = createTabPane(200, 20);
final TabPane tabPane3 = createTabPane(200, 20);
SplitPane splitPane = new SplitPane();
splitPane.setOrientation(Orientation.HORIZONTAL);
splitPane.getItems().addAll(tabPane1, tabPane2, tabPane3);
SplitPane.setResizableWithParent(tabPane1, true);
SplitPane.setResizableWithParent(tabPane2, false);
SplitPane.setResizableWithParent(tabPane3, false);
Scene scene = new Scene(splitPane);
splitPane.prefHeightProperty().bind(scene.heightProperty());
splitPane.prefWidthProperty().bind(scene.widthProperty());
stage.setScene(scene);
stage.show();
}
private TabPane createTabPane(double pref, double min) {
final TabPane tabPane = new TabPane();
Tab tab1 = new Tab("Sites");
tab1.setContent(createPane("lightgreen"));
Tab tab2 = new Tab("Favorites");
tab2.setContent(createPane("lightsteelblue"));
Tab tab3 = new Tab("Loves");
tab3.setContent(createPane("pink"));
tabPane.getTabs().addAll(tab1, tab2, tab3);
tabPane.setPrefSize(pref, 200);
tabPane.setMinSize(min, 200);
return tabPane;
}
// create a pane of a given color to hold tab content.
private Pane createPane(String color) {
final BorderPane pane = new BorderPane();
Text text = new Text();
text.textProperty().bind(pane.widthProperty().asString().concat(" x ").concat(pane.heightProperty().asString()));
pane.setCenter(text);
pane.setStyle("-fx-background-color: " + color);
return pane;
}
}