gpt4 book ai didi

java - 如何将行显示为 Accordion

转载 作者:行者123 更新时间:2023-12-02 07:05:32 30 4
gpt4 key购买 nike

我有这个显示图像的 JavaFX Accordion :

公共(public)类导航{

private static final Image BLUE_FISH = new Image("/Blue-Fish-icon.png");
private static final Image RED_FISH = new Image("/Red-Fish-icon.png");
private static final Image YELLOW_FISH = new Image("/Yellow-Fish-icon.png");
private static final Image GREEN_FISH = new Image("/Green-Fish-icon.png");

public void initNavigation(Stage primaryStage, Group root, Scene scene) {

VBox stackedTitledPanes = createStackedTitledPanes();

ScrollPane scroll = makeScrollable(stackedTitledPanes);
scroll.getStyleClass().add("stacked-titled-panes-scroll-pane");
scroll.setPrefSize(395, 580);
scroll.setLayoutX(5);
scroll.setLayoutY(32);

//scene = new Scene(scroll);
root.getChildren().add(scroll);

}

private VBox createStackedTitledPanes() {
final VBox stackedTitledPanes = new VBox();
stackedTitledPanes.getChildren().setAll(
createTitledPane("Connections", GREEN_FISH),
createTitledPane("Tables", YELLOW_FISH),
createTitledPane("Description", RED_FISH),
createTitledPane("Blue Fish", BLUE_FISH));
((TitledPane) stackedTitledPanes.getChildren().get(0)).setExpanded(true);
stackedTitledPanes.getStyleClass().add("stacked-titled-panes");

return stackedTitledPanes;
}

public TitledPane createTitledPane(String title, Image... images) {
FlowPane content = new FlowPane();
for (Image image : images) {
ImageView imageView = new ImageView(image);
content.getChildren().add(imageView);

FlowPane.setMargin(imageView, new Insets(10));
}
content.setAlignment(Pos.TOP_CENTER);

TitledPane pane = new TitledPane(title, content);
pane.getStyleClass().add("stacked-titled-pane");
pane.setExpanded(false);

return pane;
}

private ScrollPane makeScrollable(final VBox node) {
final ScrollPane scroll = new ScrollPane();
scroll.setContent(node);
scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>() {
@Override
public void changed(ObservableValue<? extends Bounds> ov, Bounds oldBounds, Bounds bounds) {
node.setPrefWidth(bounds.getWidth());
}
});
return scroll;
}

}

我感兴趣的是是否可以显示放置图像的数据行。像这样的事情:

enter image description here

P.S 案例。我有一个 java 对象,它将用作列表:

public List<dataObj> list = new ArrayList<>();

public class dataObj {

private int connectionId;
private String conenctionname;
private String connectionDescription;

public dataObj() {
}

....................
}

当我将一些数据插入Java数组列表时,我想根据上述要求将其显示到 Accordion 中。

P.S 2 就我而言,将文本插入 FlowPane 的正确方法是什么?我测试了这个:

public TitledPane createTitledPane(String title, Image... images) {
FlowPane content = new FlowPane();
for (Image image : images) {
ImageView imageView = new ImageView(image);
content.getChildren().add(imageView);

FlowPane.setMargin(imageView, new Insets(10));
}
content.setAlignment(Pos.TOP_CENTER);
content.setText("This part will be the first line.\n This part the second.");

TitledPane pane = new TitledPane(title, content);
pane.getStyleClass().add("stacked-titled-pane");
pane.setExpanded(false);

return pane;
}

我收到错误消息,使用 setText 插入文本不正确。正确的做法是什么?

最佳答案

如果使用"\n",输出字符串将被分成多行文本。例如:

component.setText("This part will be the first line.\n This part the second.");

根据您的更新,假设您有 gettersetter:

component.setText(String.valueOf(dataObj.getConnectionId()) + "\n" + dataObj.getConnectionname() + "\n" + dataObj.getConnectionDescription());

关于java - 如何将行显示为 Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16170433/

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