JavaFX:如何设置默认选择/打开的TiteledPane [英] JavaFX: How to set a TiteledPane selected/opened by default

查看:226
本文介绍了JavaFX:如何设置默认选择/打开的TiteledPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用java和 javaFX 开发一个项目,我需要知道是否有办法让第一个 TiteledPane 手风琴默认打开 ..



我的意思是舞台已加载,第一个 TiteledPane 被选中,其内容显示,无需任何用户干预。我尝试了所有建议的方法,但没有人看起来像我想要的。正如我所看到的还没有在官方文档中描述或在本网站或其他网站上给出的那样。






另外:



这是我的方法:(代码java和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);






 < ;手风琴fx:id =accord_panelayoutX =20.0layoutY =100.0prefHeight =400.0prefWidth =680.0> 
< panes>
< TitledPane fx:id =pane_araanimated =false>
< content>
< Pane prefHeight =200.0prefWidth =200.0>
< children>
< ImageView fx:id =img_unit_arafitHeight =250.0fitWidth =650.0layoutX =15.0layoutY =15.0pickOnBounds =truepreserveRatio =true>
< image>
< Image url =@ temp_5.png/>
< / image>
< / ImageView>
< / children>
< / Pane>
< / content>
< / TitledPane>
< TitledPane fx:id =pane_scianimated =false>
< content>
< Pane prefHeight =200.0prefWidth =200.0>
< children>
< ImageView fx:id =img_unit_scifitHeight =190.0fitWidth =650.0layoutX =15.0layoutY =15.0pickOnBounds =truepreserveRatio =true>
< image>
< Image url =@ temp_3.png/>
< / image>
< / ImageView>
< / children>
< / Pane>
< / content>
< / TitledPane>
< / panes>
< / Accordion>

这是例外:

  javafx.fxml.LoadException:
/C:/Users/Malek%20Boubakri/Google%20Drive/workspace/Sirat/bin/vue/Enseignant.fxml
at javafx。 fxml.FXMLLoader.constructLoadException(未知来源)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml。 FXMLLoader.loadImpl(未知来源)
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 (原生方法)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Sour ce)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke (未知来源)
at sun.reflect.GeneratedMethodAccessor1.invoke(未知来源)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)
at java.lang.reflect.Method.invoke (未知来源)
at sun.reflect.misc.MethodUtil.invoke(未知来源)
at javafx.fxml.FXMLLoader $ MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(未知来源)
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 .BasicEventDispatche r.dispatchEvent(未知来源)
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(未知来源)
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(未知来源)
at javafx.scene.Scene.impl_processMouseEvent(未知来源)
at javafx.scene.Scene $ ScenePeerL istener.mouseEvent(未知来源)
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(未知来源)
at com.sun.glass.ui.win.WinApplication $$ Lambda $ 36/2117255 219.run(未知来源)
at java.lang.Thread.run(Unknown Source)
引起:java.lang.NullPointerException
at controleur.EnsCtrl.initialize(EnsCtrl.java: 301)
... 54更多

这里是我依赖的文档中的文字。


public final void setExpandedPane(TitledPane value)



目前可见的扩展TitledPane。虽然在技术上可以将扩展窗格设置为getPanes()中不是
的值,但是这样做将由皮肤处理,就像expandedPane
为null一样。如果窗格设置为展开窗格,并且随后从getPanes()中删除
,则展开窗格将设置为null,如果
可能。 (例如,如果您已将
扩展窗格手动绑定到某个值,则无法执行此操作。)


如果任何事情都不清楚请只是评论。任何建议都会有所帮助。谢谢

解决方案

关于代码困难强烈建议刷新项目每次你工作然后从javaFX场景构建器保存FXML文件,因为eclipse不会自动执行此操作。



如果您仍然遇到一些代码问题,则验证此示例: / p>

  @FXML 
私人手风琴协议;
@FXML
private TitledPane pane1,pane2;

//代码在controller.intialize()
...
pane1.setText(TitledPane A);
pane2.setText(TitledPane B);
accord.setExpandedPane(pane1);

关于你在评论中提到的云问题,因为我知道没有伤害将工作区放在谷歌驱动器文件夹中。可能每次完成代码章节时都要进行备份,因为有时在尝试加载另一个程序已经使用的文件时会导致驱动器崩溃。 / p>

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

解决方案

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.

这篇关于JavaFX:如何设置默认选择/打开的TiteledPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆