gpt4 book ai didi

java - 编辑 Javafx Accordion 的宽度

转载 作者:行者123 更新时间:2023-12-01 04:47:50 27 4
gpt4 key购买 nike

我有一个默认太宽的 Accordion 。一段时间以来,我一直在尝试找到一种设置 Accordion 宽度的方法,但没有成功。我想让它小于默认宽度。有没有办法让这成为可能?我是不是漏掉了什么?

编辑:

这是我的代码

 public final class StudentInfo
{
private Accordion accordion;
private Pane mView;
private TextField[] mStudenInfo;
private Label[] mLabelInfo;
private HBox[] mStudentContainer;

private HBox mHBox;
private VBox mLeft;
private VBox mRight;

private Stage primaryStage;


private VBox mImageBox;


private Image mImage;
private Button mSave;
private Button mChangeImage;
private Button mResetField;
private Button mClearField;
private BorderPane mPane;

private ImageView imageView;
private GridPane mGrid;
private int mI;
public static ListView<String>[] mList;


StudentInfo()
{
primaryStage = Main.mStage;
mView = new Pane();
mGrid = new GridPane();
mPane = new BorderPane();
mHBox = new HBox();
mLeft = new VBox();
mRight = new VBox();
accordion = new Accordion();
accordion.setMaxWidth(1);
mList = new ListView[]{ new ListView<String>(),
new ListView<String>(),
new ListView<String>()};

mImageBox = new VBox();

mI = 0;

mStudenInfo = new TextField[]{new TextField(), new TextField(),
new TextField(), new TextField(),
new TextField(), new TextField(),
new TextField(), new TextField()};



mLabelInfo = new Label[]{new Label("First Name"), new Label("Last Name"),
new Label("Preffered Name"),new Label("Email"),
new Label("Phone"), new Label("City"),
new Label("State"), new Label("Major")};

mSave = new Button("Save Changes");
mChangeImage = new Button("Change Image");
mResetField = new Button ("Revert Changes");
mClearField = new Button ("Clear Information");

setGrid();
setImageBox();
setAcc();
setActions();
addToList("");
setPane();
}

public void setPane()
{
mRight.getChildren().addAll(mImageBox,mChangeImage);
mRight.setMargin(mChangeImage, new Insets(0,0,0,140));
mHBox.getChildren().addAll(mLeft,mRight);
mHBox.setMargin(mRight, new Insets(0,8000,100,0));
HBox studentIn = new HBox();
studentIn.getChildren().addAll(accordion, mHBox);
studentIn.setMargin(accordion, new Insets(10,0,0,8));
mView.getChildren().addAll(studentIn, mPane);

}


public void setImageBox()
{
Group root = new Group();

mImage = new Image(
"http://tech.massivelinks.com/uploads/google-animals.jpg");
imageView = new ImageView();
imageView.setImage(mImage);

mImageBox.getChildren().addAll(imageView);
}

public void setAcc()
{
TitledPane[] t1 = new TitledPane[]{ new TitledPane("class1", mList[0]),
new TitledPane("class2", mList[1]),
new TitledPane("class3", mList[2])};
accordion.getPanes().addAll(t1[0],t1[1],t1[2]);

}

public void setGrid()
{
mGrid.setHgap(10);
mGrid.setVgap(10);
mGrid.setPadding(new Insets(25, 25, 25, 25));

mGrid.setAlignment(Pos.CENTER);
for(mI = 0; mI < 8; mI++)
{
mGrid.add(mLabelInfo[mI],0,mI);
mGrid.add(mStudenInfo[mI],1,mI);

}
HBox textButtons = new HBox(3);
textButtons.setAlignment(Pos.CENTER);
textButtons.getChildren().addAll(mResetField, mClearField ,mSave);
mLeft.getChildren().addAll(mGrid,textButtons);
mLeft.setMargin(textButtons, new Insets(0,0,100,105));
mLeft.setMargin(mGrid, new Insets(30,0,0,0));
mI = 0;
}

public Pane getView()
{
return mView;
}

public void setActions()
{
mChangeImage.setOnAction(new EventHandler<ActionEvent>()
{
private FileChooserBuilder fcb;
private File selectedFile;
@Override
public void handle(ActionEvent Event)
{
String currentDir =
System.getProperty("user.dir") + File.separator;
StringBuilder sb = null;
fcb = FileChooserBuilder.create();

FileChooser fc =
fcb.title("Open Dialog").initialDirectory(new File(currentDir))
.build();
selectedFile = fc.showOpenDialog(Main.mStage);

if (selectedFile != null)
{
System.out.println("you selected " +

selectedFile.getName());
}
}
});
}

public static void addToList(String pName)
{
mList[0].getItems().add("any Name here");//pName);

}
}

我尝试使用accordion.setMaxWidth,但它不会改变 Accordion 的宽度。

最佳答案

我发现了我的问题。 Accordion 的大小超出了 Accordion 中 ListView 的大小。通过在 ListView 上设置最大宽度,它将更改折叠选项卡的大小。

例如:

mList[0].setMaxWidth(10);

关于java - 编辑 Javafx Accordion 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15529317/

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