如何在手风琴面板上设置不同的高度?

时间:2013-11-22 17:03:14

标签: javafx-2 javafx accordion fxml scene

有没有办法让JavaFX中的手风琴中的面板具有不同的高度?我想知道怎么做。我用谷歌搜索了它,但我还没找到我需要的东西。

2 个答案:

答案 0 :(得分:0)

试试这个:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class TitledPaneSample extends Application
{
final String[]     imageNames = new String[]{
    "Apples", "Flowers", "Leaves"};
final Image[]      images     = new Image[imageNames.length];
final ImageView[]  pics       = new ImageView[imageNames.length];
final TitledPane[] tps        = new TitledPane[imageNames.length];

public static void main(String[] args)
{
    launch(args);
}

@Override
public void start(Stage stage)
{
    stage.setTitle("TitledPane");
    Scene scene = new Scene(new Group(), 380, 380);
    scene.setFill(Color.GHOSTWHITE);

    final Accordion accordion = new Accordion();

    for (int i = 0; i < imageNames.length; i++)
    {
        images[i] = new Image(getClass().getResourceAsStream(imageNames[i]
            + ".jpg"));
        pics[i] = new ImageView(images[i]);
        tps[i] = new TitledPane(imageNames[i], pics[i]);
        tps[i].setMinHeight(i * 100);
    }
    accordion.getPanes().addAll(tps);
    accordion.setExpandedPane(tps[0]);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(accordion);
    stage.setScene(scene);
    stage.show();
}
}

除上述代码外,您还需要将三个文件放在正确的位置。

答案 1 :(得分:0)

您可以使用setPrefHeight窗格来执行此操作....

试试这个。

pane.setPrefHeight(400);