SenSok
SenSok

Reputation: 138

Editing the width of a Javafx accordion

I have an accordion that is at default too wide. I have been trying to find a way to set a width on the accordion for a while, but to no prevail. I want to make it smaller than the default width. Is there a way to make this possible? Have I been missing something?

EDIT:

Here is my code

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

   }
}

I have tried using the accordion.setMaxWidth, but it does not change the width of the accordion.

Upvotes: 1

Views: 1426

Answers (1)

SenSok
SenSok

Reputation: 138

I found my problem. The accordion was going off of the size of the list view in the accordion. By setting a max width on the list view, it will change the size of the accordion tabs.

for example:

mList[0].setMaxWidth(10);

Upvotes: 1

Related Questions