11

I am working on a project using java and javaFX, i need to know if there is a way to have the first TiteledPane in the Accordion opened by default..

I mean when the stage is loaded, the first TiteledPane is selected and its content showed without any user's intervention. i tried all suggested methods but no one look like what i want. As i see also no described one in the official documentation or given in this site or other is like.


IN ADDITION:

here is my approach:(Code java and FXML)

@FXML
private Accordion accord_pane;
@FXML
private TitledPane pane_ara,pane_sci,pane_soc,pane_art,pane_spo,pane_fra,pane_ang;

...

pane_ara.setText("TitledPane A");
pane_sci.setText("TitledPane B");

accord_pane.setExpandedPane(pane_ara);

               <Accordion fx:id="accord_pane" layoutX="20.0" layoutY="100.0" prefHeight="400.0" prefWidth="680.0">
                  <panes>
                    <TitledPane fx:id="pane_ara" animated="false">
                         <content>
                            <Pane prefHeight="200.0" prefWidth="200.0">
                               <children>
                                  <ImageView fx:id="img_unit_ara" fitHeight="250.0" fitWidth="650.0" layoutX="15.0" layoutY="15.0" pickOnBounds="true" preserveRatio="true">
                                     <image>
                                        <Image url="@temp_5.png" />
                                     </image>
                                  </ImageView>
                               </children>
                            </Pane>
                         </content>
                    </TitledPane>
                      <TitledPane fx:id="pane_sci" animated="false">
                         <content>
                            <Pane prefHeight="200.0" prefWidth="200.0">
                               <children>
                                  <ImageView fx:id="img_unit_sci" fitHeight="190.0" fitWidth="650.0" layoutX="15.0" layoutY="15.0" pickOnBounds="true" preserveRatio="true">
                                     <image>
                                        <Image url="@temp_3.png" />
                                     </image>
                                  </ImageView>
                               </children>
                            </Pane>
                         </content>
                      </TitledPane>
                     </panes>
                   </Accordion>

here is the exception:

javafx.fxml.LoadException: 
/C:/Users/Malek%20Boubakri/Google%20Drive/workspace/Sirat/bin/vue/Enseignant.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at vue.Enseignant.start(Enseignant.java:18)
at vue.Index.stageCtrlHandler(Index.java:85)
at controleur.MenuCtrl.click_btn(MenuCtrl.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$ClickGenerator.postProcess(Unknown Source)
at javafx.scene.Scene$ClickGenerator.access$8100(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$165/775736639.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at controleur.EnsCtrl.initialize(EnsCtrl.java:301)
    ... 54 more

here is the text from documentation that i lean on.

public final void setExpandedPane(TitledPane value)

The expanded TitledPane that is currently visible. While it is technically possible to set the expanded pane to a value that is not in getPanes(), doing so will be treated by the skin as if expandedPane is null. If a pane is set as the expanded pane, and is subsequently removed from getPanes(), then expanded pane will be set to null, if possible. (This will not be possible if you have manually bound the expanded pane to some value, for example).

If any thing is not clear please just comment. Any suggestion will be helpful..Thanks

Community
  • 1
  • 1
Malek Boubakri
  • 820
  • 2
  • 17
  • 36
  • 2
    "I tried all suggested methods". Please create a [MCVE] showing what you tried and [edit] your question to include it. – James_D Oct 18 '15 at 13:39
  • Please check it again, i do what i could and i'm really need help here.. thanks – Malek Boubakri Oct 18 '15 at 14:43
  • 1
    Your code looks correct. I guess you didn't read the link in my previous comment: please post a [MCVE]. – James_D Oct 18 '15 at 15:03
  • I don't get what i should add or remove from the question.. and -2 is all what i got.. if possible, please tell me what wrong in my question @James_D and thanks. sorry for my bad english.. – Malek Boubakri Oct 18 '15 at 15:21
  • 1
    As it says in the link, your example code should be *minimal* (only what you need to show the problem, eg you need an accordion and at most 2 titled panes (not 7), and nothing else); it should be *complete* (complete classes and fxml files, enough to actually execute it, not code snippets like you have), and *verifiable* (compiles and runs and demonstrates the problem). Start from scratch, create a ***new project*** that only has an accordion with two titled panes, and try to get it to expand one titled pane at startup. If you can't, then post the code. – James_D Oct 18 '15 at 15:27
  • 1
    And only now do you even mention that you get an exception? Don't you think this would have been useful information before? – James_D Oct 18 '15 at 15:30
  • hhhh.. my fault, i think it's complete right now. – Malek Boubakri Oct 18 '15 at 15:39
  • In what possible sense is that "complete"? – James_D Oct 18 '15 at 15:49
  • 1
    I mean "correct question form" :( – Malek Boubakri Oct 18 '15 at 15:51
  • can you please post codes from `Enseignant` class especially line 15 all to 85, okay. – Elltz Oct 21 '15 at 22:40
  • Do you mean Enseignant controler class or the FXML file?? – Malek Boubakri Oct 21 '15 at 23:50
  • 1
    just the controller class @MalekBoubakri – Elltz Oct 22 '15 at 16:18
  • i think the problem is outside the code because when i tested it in another new package (in netbeans) it works!!! i'm using eclipse mars and i really think to move back to luna.. :/ i dont know if putting the workpace in google cloud can damage something! i noticed that when i start eclipse google cloud get crashed.. – Malek Boubakri Oct 22 '15 at 20:13

2 Answers2

25

For those who want to include the default expanded pane in the FXML rather than in code:

<Accordion expandedPane="$myPane">
    <panes>
      <TitledPane fx:id="myPane">
          ...
      </TitledPane>
      <TitledPane>
          ...
      </TitledPane>
    </panes>
</Accordion>
Zxifer
  • 413
  • 1
  • 4
  • 9
11

About the code difficulties it's highly recommended to refresh your project everytime you work on then save an FXML file from javaFX scene builder because eclipse dont do that automatically.

if you still hve some code problemes,this exemple is verified:

@FXML
private Accordion accord;
@FXML
private TitledPane pane1,pane2;

//codes in controller.intialize()
...
    pane1.setText("TitledPane A");
    pane2.setText("TitledPane B");
    accord.setExpandedPane(pane1);

And about the cloud problem you mentioned in the comment, as i know there is no harm on putting the workspace in google drive folder.May be it would be better if you do backup every time you finish a chapter of code, because sometimes drive crash when he try to load a file already used by another program.