1

我有一个默认太宽的手风琴。一段时间以来,我一直试图找到一种方法来设置手风琴的宽度,但没有成功。我想让它小于默认宽度。有没有办法让这成为可能?我错过了什么吗?

编辑:

这是我的代码

 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);

   }
}

我曾尝试使用手风琴.setMaxWidth,但它不会改变手风琴的宽度。

4

1 回答 1

1

我发现了我的问题。手风琴的大小超出了手风琴列表视图的大小。通过在列表视图上设置最大宽度,它将更改手风琴选项卡的大小。

例如:

mList[0].setMaxWidth(10);
于 2013-03-21T21:33:05.167 回答