【发布时间】:2014-07-01 12:02:59
【问题描述】:
我有一个带有多个 titledPane 的 Accordion,并且 titledPane 的 ListView 面板中有很多数据。我只想在搜索数据时展开 Accordion 的所有 titledPane。我不知道该怎么做。有什么想法吗?
在这里,我附上了我真实项目的屏幕截图,它实际上显示了我想要做什么。
【问题讨论】:
标签: java javafx accordion expandable
我有一个带有多个 titledPane 的 Accordion,并且 titledPane 的 ListView 面板中有很多数据。我只想在搜索数据时展开 Accordion 的所有 titledPane。我不知道该怎么做。有什么想法吗?
在这里,我附上了我真实项目的屏幕截图,它实际上显示了我想要做什么。
【问题讨论】:
标签: java javafx accordion expandable
快速回答:你不能。
Accordion 有一个expandedPane 属性,即单个TitledPane。 Accordion 无法拥有多个展开的窗格。
相反,您可以直接使用多个TitledPanes(在VBox 或类似的内部),以获得您想要的行为。不幸的是,这看起来不像Accordion,因为TitledPanes 默认使用不同的样式。但是使用一些自定义 CSS(查看 caspian.css 以了解手风琴的样式),您可以使其看起来就像在 Accordion 中的窗格一样。
稍微多做一些工作,您就可以将其放入您自己的“多选手风琴”控件中,以便于重用。
【讨论】:
就像哈罗德说的。你不能。但是你可以在另一个容器中使用多个TitledPane。 VBox 例如。试试这个代码 sn-p。
import java.util.ArrayList;
import java.util.Collection;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TitledPanes extends Application {
public static void main(String [] args){ launch(args); }
@Override
public void start(Stage primaryStage) throws Exception {
HBox root = new HBox();
VBox noaccordion = new VBox();
noaccordion.getChildren().addAll(this.createPanes());
VBox yesaccordion = new VBox();
Accordion acc = new Accordion();
acc.getPanes().addAll(this.createPanes());
yesaccordion.getChildren().add(acc);
root.getChildren().addAll(noaccordion, yesaccordion);
primaryStage.setScene(new Scene(root,800,400));
primaryStage.show();
}
private Collection<TitledPane> createPanes(){
Collection<TitledPane> result = new ArrayList<TitledPane>();
TitledPane tp = new TitledPane();
tp.setText("Pane 1");
tp.setContent(new TextArea("Random text..."));
result.add(tp);
tp = new TitledPane();
tp.setText("Pane 2");
tp.setContent(new TextArea("Random text..."));
result.add(tp);
tp = new TitledPane();
tp.setText("Pane 3");
tp.setContent(new TextArea("Random text..."));
result.add(tp);
return result;
}
}
【讨论】: