[英]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.