有没有办法让JavaFX中的手风琴中的面板具有不同的高度?我想知道怎么做。我用谷歌搜索了它,但我还没找到我需要的东西。
答案 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);