3 Replies Latest reply on Nov 15, 2012 9:02 PM by user2969435

    TitledPane and Accordion


      I just want to know whether TitledpPane can contain many children buttons.
      I can't solve the solution

      For example;

      Accordion accordion = new Accordion();
      Button clientButton = new Button("Client");
      Button userButton = new Button("User");
      TitledPane adminPane = new TitledPane("Adminstration",200,350);

      Button vclientButton = new Button("Client");
      Button vuserButton = new Button("User");
      TitledPane viewPane = new TitledPane("View",200,350);

      In Google Web Toolkit (GWT), you can do above example without any problem.

      Please advise me what to do.

      Thank you.
        • 1. Re: TitledPane and Accordion
          I wonder what toolkit or version of JavaFX your code is written in.
          TitledPane adminPane = new TitledPane("Adminstration",200,350);
          The above code does not compile with JavaFX 2.1b17 as there is no such constructor for TitledPane.
          This makes it more difficult to help troubleshoot what your issue may be.

          Perhaps the sample code below can help you:
          import javafx.application.Application;
          import javafx.scene.Scene;
          import javafx.scene.control.*;
          import javafx.scene.layout.*;
          import javafx.stage.Stage;
          public class AccordionChildren extends Application {
            public static void main(String[] args) { launch(args); }
            @Override public void start(Stage primaryStage) {
              TitledPane adminPane = new TitledPane("Administration", 
                VBoxBuilder.create().style("-fx-padding: 10").spacing(10).children(
                  ButtonBuilder.create().text("Admin Client").maxWidth(Double.MAX_VALUE).build(),
                  ButtonBuilder.create().text("Admin User").maxWidth(Double.MAX_VALUE).build()
              TitledPane viewPane = new TitledPane("View", 
                VBoxBuilder.create().style("-fx-padding: 10").spacing(10).children(
                  ButtonBuilder.create().text("View Client").maxWidth(Double.MAX_VALUE).build(),
                  ButtonBuilder.create().text("View User").maxWidth(Double.MAX_VALUE).build()
              Accordion accordion = new Accordion();
              accordion.getPanes().addAll(adminPane, viewPane);
              StackPane layout = new StackPane();
              layout.setStyle("-fx-padding: 10; -fx-background-color: cornsilk;");
              primaryStage.setScene(new Scene(layout));
          Accordion is a rather strange control to use for your UI as it makes it look really tall and skinny and only one pane in an Accordion can be open at a time and it fills the entire tall skinny area, making for an awkward user experience when you want to switch from one pane to another.

          Maybe you want a sidebar control with stacked TitlePanes - there is a Jira request for such a thing (http://javafx-jira.kenai.com/browse/RT-19248 "StackedTitledPanes control"), but it has not been implemented yet.

          You could read through this thread to get more insight: TitledPane in a VBox ... TitledPane ignores maxSize "TitledPane in a VBox"
          • 2. Re: TitledPane and Accordion
            Thank you for advise.

            I guess I will have to wait for latest Javafx version. In meantime I will go for Accordion.


            • 3. Re: TitledPane and Accordion
              You can put a listview inside every single accordion and if you don´t like having a text instead a button you can use list.setCellFactory like the example provided by oracle. Instead of using the Rectangle class use the Button Class so you can have a variable listview with buttons. I made something similar in FXML so you´ll have an idea.
              <Accordion minWidth="-Infinity" prefHeight="600.0" prefWidth="200.0">
                                              <TitledPane fx:id="x1" animated="false" minWidth="200.0" prefHeight="379.0" prefWidth="200.0" text="Vectores">
                                                      <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                                                              <ListView id="listaVectores" fx:id="idLlist" onMouseClicked="#handleListMouseClick" layoutX="-4.0" layoutY="0.0" prefHeight="518.0" prefWidth="200.0">
                                                                      <FXCollections fx:factory="observableArrayList">
                                                                          <String fx:value="Item 1" />
                                                                          <String fx:value="Item 2" />
                                                                          <String fx:value="Item3" />