JavaFX 更改标题面板图标的标题

4

我是JavaFX的新手。在我的应用程序中,我使用了TitledPane,并且希望将默认的最小化图标位置从左侧更改为右侧。问题是我使用单独的FXML文件来创建TitledPane并将其包含在场景中。我使用以下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: "";

起初,我尝试使用上述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");
    }     
}

但是这并没有起作用。我认为我使用的方法不对。有人能帮我吗?

这是一个非常糟糕的黑客,我不准备把它作为答案提出。 你需要在场景实际显示后执行此代码:Node arrowButton = titledPane.lookup(".arrow-button"); arrowButton.translateXProperty().bind(titledPane.widthProperty().subtract(32)); - James_D
1个回答

0
尝试这个解决方案:如何在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()
);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接