JavaFX更改标题窗格图标的标题

时间:2021-02-24 16:59:53

I am new to JavaFX. In my application I am using Titled pane and I want to replace the default minimise icon location from left to right end. The thing is I am using a separate FXML file for the titled pane and it is included in the scene. I used the below css content to achieve my goal.

我是JavaFX的新手。在我的应用程序中,我使用标题窗格,我想从左到右替换默认的最小化图标位置。问题是我正在为标题窗格使用单独的FXML文件,它包含在场景中。我用下面的css内容来实现我的目标。

.titled-pane > .title > .arrow-button .arrow {
-fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
-fx-background-insets: 1 0 -1 0, 0;
-fx-padding: 0.25em 0.3125em 0.25em 0.3125em; /* 3 3.75 3 3.75 */
-fx-collapsible: false;
-fx-shape: "";

At first I tried to remove the icon using the above css.

起初我尝试使用上面的css删除图标。

public class PrjExplorerController implements Initializable {

    @FXML
    TitledPane titledPanePrjExplorer;


    @Override
    public void initialize(URL url, ResourceBundle rb) {


        titledPanePrjExplorer.getStylesheets().add("StyleSheet.css");
        boolean b = titledPanePrjExplorer.getStyleClass().add("titled-pane");
    }     
}

But this not working. I think I am using a wrong approach. Could anyone help me on this?

但这不起作用。我想我使用的是错误的做法。有人可以帮我吗?

1 个解决方案

#1


0  

Try this solution: How to change header component in TitledPane in JavaFX Specifically:

试试这个解决方案:如何在JavaFX中改变TitledPane中的标题组件具体来说:

// translate the titledpane arrow and header so that the arrow is displayed to right of the header.
Pane connectivityArrow = (Pane) connectivityPane.lookup(".arrow");
connectivityArrow.translateXProperty().bind(
  connectivityPane.widthProperty().subtract(connectivityArrow.widthProperty().multiply(2))
);
Pane connectivityTitle = (Pane) connectivityPane.lookup(".header");
connectivityTitle.translateXProperty().bind(
  connectivityArrow.widthProperty().negate()
);

#1


0  

Try this solution: How to change header component in TitledPane in JavaFX Specifically:

试试这个解决方案:如何在JavaFX中改变TitledPane中的标题组件具体来说:

// translate the titledpane arrow and header so that the arrow is displayed to right of the header.
Pane connectivityArrow = (Pane) connectivityPane.lookup(".arrow");
connectivityArrow.translateXProperty().bind(
  connectivityPane.widthProperty().subtract(connectivityArrow.widthProperty().multiply(2))
);
Pane connectivityTitle = (Pane) connectivityPane.lookup(".header");
connectivityTitle.translateXProperty().bind(
  connectivityArrow.widthProperty().negate()
);