简体   繁体   English

如何在选项卡的右侧显示关闭按钮

[英]How to display close button on the right hand side in the Tab

移动关闭按钮太右侧

As you can see currently the close button is at the top. 正如您所看到的,关闭按钮位于顶部。

How can i place it on the right hand side ? 我怎么把它放在右手边?

public class TabbedPaneTest extends Application
{
  @Override
  public void start(Stage primaryStage)
  {
    primaryStage.setTitle("TabPane Test");

    TabPane tabPane = new TabPane();
    tabPane.setStyle("-fx-tab-min-height: 100");
    tabPane.setRotateGraphic(true);
    tabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS);

    tabPane.getTabs().addAll(tab("Tab 1"), tab("Tab 2"));
    tabPane.setSide(Side.LEFT);

    primaryStage.setScene(new Scene(tabPane, 400, 200));
    primaryStage.show();
  }

  static Tab tab(String labelText)
  {
    Tab tab = new Tab();
    Label label = new Label(labelText);
    label.setRotate(90);
    tab.setGraphic(new StackPane(label));
    tab.setContent(new Label("       " + labelText + " content"));
    return tab;
  }

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

This will be a little bit hacky. 这将是一个有点hacky。

Based on the CSS reference of TabPane and the source code of TabPaneSkin : a Tab contains a StackPane that contains a Label , the close Button and the focus indicator. 基于所述CSS参考TabPane和的源代码TabPaneSkin :一个Tab包含StackPane包含Label ,关闭Button和焦点指示符。 This StackPane has the style class tab-container . StackPane具有样式类tab-container

So you can rotate this StackPane in CSS: 所以你可以在CSS中旋转这个StackPane

.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container {
   -fx-rotate:90;
}

After rotating the StackPane I have noticed, that the focus indicator is handled differently, so that one must be also rotated (it has the style class focus-indicator ). 旋转StackPane我注意到,焦点指示器的处理方式不同,因此必须旋转focus-indicator (它具有样式类focus-indicator )。

.tab-pane > .tab-header-area > .headers-region > .tab * .focus-indicator {
   -fx-rotate:-90;
}

An example , that the same as yours, just the style-sheet is added, and the Label on the Tab is not rotated anymore: 一个例子 ,你的一样,只是在样式表是,并且将Label上的Tab不再被转动:

public class TabbedPaneTest extends Application {
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("TabPane Test");

        TabPane tabPane = new TabPane();
        tabPane.setStyle("-fx-tab-min-height: 100");
        tabPane.setRotateGraphic(true);
        tabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS);

        tabPane.getTabs().addAll(tab("Tab 1"), tab("Tab 2"));
        tabPane.setSide(Side.LEFT);

        Scene scene = new Scene(tabPane, 400, 200);
        scene.getStylesheets().add(getClass().getResource("application.css").toString());

        primaryStage.setScene(scene);
        primaryStage.show();
    }

    static Tab tab(String labelText) {
        Tab tab = new Tab();
        Label label = new Label(labelText);

        tab.setGraphic(new StackPane(label));
        tab.setContent(new Label("       " + labelText + " content"));
        return tab;
    }

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

But you can also use this approach without using a graphic on the Tab : 但您也可以使用此方法而不使用Tab上的图形:

static Tab tab(String labelText) {
    Tab tab = new Tab(labelText);
    tab.setContent(new Label("       " + labelText + " content"));
    return tab;
}

This will produce a TabPane like on the picture: 这将在图片上生成一个TabPane

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JAPE右侧制作if-else语句? - How to make if-else statement in JAPE right hand side? 如何从结果内部/右侧获取条件/左侧定义的所有流口水变量的列表? - How to get a list of all drools variables defined in condition / left hand side from inside the consequence / right hand side? 在Java 6中使用Generics在右侧? - Using Generics on right hand side in Java 6? 如何向JTabbedPane标签添加关闭按钮? - How to add close button to a JTabbedPane Tab? 如何始终使右侧JPanel显示 - how to make a right side JPanel display always 如何在菜单项的右侧显示图标? - How to display icon on the right side of menu items? Java的逻辑OR运算符不评估右侧,尽管右侧具有一元运算符? - Java's logical OR operator does not evaluate right hand side despite that right hand side has a unary operator? JFreeChart:如何将 Y 轴从左侧移动到右侧? - JFreeChart: how to move Y-axis from left to right hand side? Hibernate多对多关联:左侧收集包含元素,但右侧收集是空的 - Hibernate Many-to-many association: left hand side collection contains elements, but right hand side collection is empty 如何仅在所需选项卡中显示带有图像的按钮? - How to display a button with an image only in the desired tab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM