如何在TabPane中隐藏TabBar? [英] How to hide the TabBar in TabPane?

查看:883
本文介绍了如何在TabPane中隐藏TabBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 TabPane 构建下一个/上一个窗口。我决定使用 TabPane ,因为它易于在 SceneBuilder 中使用和设计。在应用程序开始时,我用它来暂时隐藏 TabBar -

I am trying to build a Next/Previous windows using TabPane. I decided to use TabPane as it is easy to use and design in SceneBuilder. At the start fo the app, I used this to hide the TabBar for now-

tabPane.setTabMinHeight(-10);
tabPane.setTabMaxHeight(-10);

此后TabPane的外观 -

The appearance of the TabPane after this-

正如您所看到的,仍然只有 TabBar 的一小部分(下面)标题栏)。如何完全隐藏它,以便我的 TabPane 看起来只是一个普通的 Pane 但是它的所有功能都完好无损?

As you can see, there still remains a small part of TabBar (below the titlebar). How can I hide it completely so that my TabPane will look like just a normal Pane but with all its functionality intact?

推荐答案

使用隐藏标签作为向导类型界面的 TabPane 是一个有趣的想法,我没有想到并认为我喜欢。

Using a TabPane with hidden tabs as a wizard-type interface is an interesting idea, which I hadn't thought of and think I like.

您可以在外部CSS文件中隐藏以下标签:

You can hide the tabs with the following in an external CSS file:

.tab-pane {
    -fx-tab-max-height: 0 ;
} 
.tab-pane .tab-header-area {
    visibility: hidden ;
}

这是一个SSCCE。在这里我给了选项卡窗格CSS类向导

Here's a SSCCE. In this I gave the tab pane the CSS class wizard.

import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class TabPaneAsWizard extends Application {

    @Override
    public void start(Stage primaryStage) {
        TabPane tabPane = new TabPane();
        tabPane.getStyleClass().add("wizard");
        for (int i = 1; i<=10; i++) {
            tabPane.getTabs().add(createTab(i));
        }
        Button previous = new Button("Previous");
        previous.setOnAction(e -> 
            tabPane.getSelectionModel().select(tabPane.getSelectionModel().getSelectedIndex()-1));
        previous.disableProperty().bind(tabPane.getSelectionModel().selectedIndexProperty().lessThanOrEqualTo(0));
        Button next = new Button("Next");
        next.setOnAction(e ->
            tabPane.getSelectionModel().select(tabPane.getSelectionModel().getSelectedIndex()+1));
        next.disableProperty().bind(
                tabPane.getSelectionModel().selectedIndexProperty().greaterThanOrEqualTo(
                        Bindings.size(tabPane.getTabs()).subtract(1)));

        HBox buttons = new HBox(20, previous, next);
        buttons.setAlignment(Pos.CENTER);

        BorderPane root = new BorderPane(tabPane, null, null, buttons, null);
        Scene scene = new Scene(root, 600, 600);
        scene.getStylesheets().add("tab-pane-as-wizard.css");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private Tab createTab(int id) {
        Tab tab = new Tab();
        Label label = new Label("This is step "+id);
        tab.setContent(label);
        return tab ;
    }

    public static void main(String[] args) {
        launch(args);
    }
}

tab-pane-as-wizard.css:

tab-pane-as-wizard.css:

.wizard {
    -fx-tab-max-height: 0 ;
} 
.wizard .tab-header-area {
    visibility: hidden ;
}

这篇关于如何在TabPane中隐藏TabBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆