use of com.jfoenix.controls.JFXTabPane in project JFoenix by jfoenixadmin.
the class JFXTabPaneSkin method layoutChildren.
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
final double headerHeight = snapSize(header.prefHeight(-1));
final Side side = getSkinnable().getSide();
double tabsX = side == Side.RIGHT ? x + w - headerHeight : x;
double tabsY = side == Side.BOTTOM ? y + h - headerHeight : y;
final int rotation = getRotation(side);
// update header
switch(side) {
case TOP:
header.resize(w, headerHeight);
header.relocate(tabsX, tabsY);
break;
case LEFT:
header.resize(h, headerHeight);
header.relocate(tabsX + headerHeight, h - headerHeight);
break;
case RIGHT:
header.resize(h, headerHeight);
header.relocate(tabsX, y - headerHeight);
break;
case BOTTOM:
header.resize(w, headerHeight);
header.relocate(w, tabsY - headerHeight);
break;
}
header.getTransforms().setAll(new Rotate(rotation, 0, headerHeight, 1));
// update header clip
// header.clip.setX(0);
// header.clip.setY(0);
// header.clip.setWidth(isHorizontal() ? w : h);
// header.clip.setHeight(headerHeight + 10); // 10 is the height of the shadow effect
// position the tab content of the current selected tab
double contentStartX = x + (side == Side.LEFT ? headerHeight : 0);
double contentStartY = y + (side == Side.TOP ? headerHeight : 0);
double contentWidth = w - (isHorizontal() ? 0 : headerHeight);
double contentHeight = h - (isHorizontal() ? headerHeight : 0);
// update tabs container
tabsClip.setWidth(contentWidth);
tabsClip.setHeight(contentHeight);
tabsContainerHolder.resize(contentWidth, contentHeight);
tabsContainerHolder.relocate(contentStartX, contentStartY);
tabsContainer.resize(contentWidth * tabContentHolders.size(), contentHeight);
for (int i = 0, max = tabContentHolders.size(); i < max; i++) {
TabContentHolder tabContentHolder = tabContentHolders.get(i);
tabContentHolder.setVisible(true);
tabContentHolder.setTranslateX(contentWidth * i);
if (tabContentHolder.getClip() != null) {
((Rectangle) tabContentHolder.getClip()).setWidth(contentWidth);
((Rectangle) tabContentHolder.getClip()).setHeight(contentHeight);
}
if (tabContentHolder.tab == selectedTab) {
int index = getSkinnable().getTabs().indexOf(selectedTab);
if (index != i) {
tabsContainer.setTranslateX(-contentWidth * i);
diffTabsIndices = i - index;
} else {
// fix X translation after changing the tabs
if (diffTabsIndices != 0) {
tabsContainer.setTranslateX(tabsContainer.getTranslateX() + contentWidth * diffTabsIndices);
diffTabsIndices = 0;
}
// animate upon tab selection only otherwise just translate the selected tab
if (isSelectingTab && !((JFXTabPane) getSkinnable()).isDisableAnimation()) {
new CachedTransition(tabsContainer, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(tabsContainer.translateXProperty(), -contentWidth * index, Interpolator.EASE_BOTH)))) {
{
setCycleDuration(Duration.seconds(0.320));
setDelay(Duration.seconds(0));
}
}.play();
} else {
tabsContainer.setTranslateX(-contentWidth * index);
}
}
}
tabContentHolder.resize(contentWidth, contentHeight);
// tabContentHolder.relocate(contentStartX, contentStartY);
}
}
use of com.jfoenix.controls.JFXTabPane in project JFoenix by jfoenixadmin.
the class TabsDemo method start.
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Tabs");
JFXTabPane tabPane = new JFXTabPane();
Tab tab = new Tab();
tab.setText(msg);
tab.setContent(new Label(TAB_0));
tabPane.getTabs().add(tab);
tabPane.setPrefSize(300, 200);
Tab tab1 = new Tab();
tab1.setText(TAB_01);
tab1.setContent(new Label(TAB_01));
tabPane.getTabs().add(tab1);
SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
selectionModel.select(1);
JFXButton button = new JFXButton("New Tab");
button.setOnMouseClicked((o) -> {
Tab temp = new Tab();
int count = tabPane.getTabs().size();
temp.setText(msg + count);
temp.setContent(new Label(TAB_0 + count));
tabPane.getTabs().add(temp);
});
tabPane.setMaxWidth(500);
HBox hbox = new HBox();
hbox.getChildren().addAll(button, tabPane);
hbox.setSpacing(50);
hbox.setAlignment(Pos.CENTER);
hbox.setStyle("-fx-padding:20");
Group root = new Group();
Scene scene = new Scene(root, 700, 250);
root.getChildren().addAll(hbox);
scene.getStylesheets().add(TabsDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());
primaryStage.setTitle("JFX Tabs Demo");
primaryStage.setScene(scene);
primaryStage.show();
}
Aggregations