gpt4 book ai didi

java - 如何在 JavaFX 中展开和折叠 TitledPane

转载 作者:行者123 更新时间:2023-12-01 10:50:09 27 4
gpt4 key购买 nike

所以,这是我现在拥有的代码:

    SplitPane sp = new SplitPane();
final StackPane sp1 = new StackPane();

final Accordion accordion = new Accordion ();

TitledPane tp1 = new TitledPane();
tp1.setText("First");
TitledPane tp2 = new TitledPane();
tp2.setText("Second");
TitledPane tp3 = new TitledPane();
tp3.setText("Third");

accordion.getPanes().add(tp1);
accordion.getPanes().add(tp2);
accordion.getPanes().add(tp3);


sp1.getChildren().add(accordion);

final StackPane sp2 = new StackPane();
sp.getItems().addAll( sp1 , sp2 );
double height = Screen.getPrimary().getVisualBounds().getHeight();
double width = Screen.getPrimary().getVisualBounds().getWidth();
Scene scene = new Scene( sp );
primaryStage.setScene( scene );
primaryStage.setMaximized( true );
primaryStage.setMinHeight( height );
primaryStage.setMinWidth( width );
primaryStage.show();
sp.setDividerPositions(0.3);

如您所见,我有一个 Accordion ,里面有三个 TitledPane。我想要的是,当用户单击 TitledPaned 时,它应该扩展到其父对象(在本例中为 Accordion )的完整高度。但我不知道该怎么做。这就是我现在拥有的:

enter image description here

请注意,在上图中,即使第一个面板被激活,它也不会展开。这就是我想要的:

enter image description here

(我手动创建了最后一张图片)。谢谢!

最佳答案

我认为,您需要调用setContent()方法。

示例:

        TextField firstNameFld = new TextField();
firstNameFld.setPrefColumnCount(8);
TextField lastNameFld = new TextField();
lastNameFld.setPrefColumnCount(8);
GridPane grid = new GridPane();
grid.addRow(0, new Label("First Name:"), firstNameFld);
grid.addRow(1, new Label("Last Name:"), lastNameFld);
tp1.setContent(grid);
tp2.setContent(new Label("tp2............."));
tp3.setContent(new Label("tp3.............."));

关于java - 如何在 JavaFX 中展开和折叠 TitledPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33963323/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com