Javafx 2 如何在手风琴面板上设置不同的高度?
在JavaFX中有没有一种方法可以在手风琴中使用不同高度的面板?我想知道怎么做。我在谷歌上搜索过,但还没有找到我需要的东西 试试这个:Javafx 2 如何在手风琴面板上设置不同的高度?,javafx-2,javafx,accordion,fxml,scene,Javafx 2,Javafx,Accordion,Fxml,Scene,在JavaFX中有没有一种方法可以在手风琴中使用不同高度的面板?我想知道怎么做。我在谷歌上搜索过,但还没有找到我需要的东西 试试这个: import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Accordion; import javafx.scene.control.TitledPane; import jav
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();
}
}
导入javafx.application.application;
导入javafx.scene.Group;
导入javafx.scene.scene;
导入javafx.scene.control.Accordion;
导入javafx.scene.control.TitledPane;
导入javafx.scene.image.image;
导入javafx.scene.image.ImageView;
导入javafx.scene.paint.Color;
导入javafx.stage.stage;
公共类标题窗格示例扩展了应用程序
{
最终字符串[]图像名称=新字符串[]{
“苹果”、“花”、“叶”};
最终图像[]图像=新图像[imageNames.length];
final ImageView[]pics=新ImageView[imageNames.length];
最终标题窗格[]tps=新标题窗格[imageNames.length];
公共静态void main(字符串[]args)
{
发射(args);
}
@凌驾
公众假期开始(阶段)
{
舞台布景标题(“标题窗格”);
场景=新场景(新组(),380,380);
场景.setFill(颜色.ghostwite);
最终手风琴=新手风琴();
对于(int i=0;i
除上述代码外,您只需将这三个文件放置在正确的位置。您可以使用窗格的
setPrefHeight
来完成此操作
试试这个
pane.setPrefHeight(400);
我不完全明白你说的,如果你想在初始时间设置所有不同大小的窗格,那么我在下面给出答案。如果是其他事情,请告诉我?谢谢你的帮助。我以前试过这个,但没用,我发现这和我在电脑上所做的改变有关stylesheet@Andre它在初始时间和它的完美…如果你想设置一些改变,然后你可以使用事件…如果你有一些更多的问题,告诉我一些细节