久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='iHGjx'><tr id='iHGjx'><dt id='iHGjx'><q id='iHGjx'><span id='iHGjx'><b id='iHGjx'><form id='iHGjx'><ins id='iHGjx'></ins><ul id='iHGjx'></ul><sub id='iHGjx'></sub></form><legend id='iHGjx'></legend><bdo id='iHGjx'><pre id='iHGjx'><center id='iHGjx'></center></pre></bdo></b><th id='iHGjx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iHGjx'><tfoot id='iHGjx'></tfoot><dl id='iHGjx'><fieldset id='iHGjx'></fieldset></dl></div>
    <tfoot id='iHGjx'></tfoot>

        <small id='iHGjx'></small><noframes id='iHGjx'>

        <legend id='iHGjx'><style id='iHGjx'><dir id='iHGjx'><q id='iHGjx'></q></dir></style></legend>
          <bdo id='iHGjx'></bdo><ul id='iHGjx'></ul>

        無法從 JavaFX 中的 MenuItem 獲取場景

        Unable to get Scene from MenuItem in JavaFX(無法從 JavaFX 中的 MenuItem 獲取場景)
        <tfoot id='UzHRI'></tfoot>

        <small id='UzHRI'></small><noframes id='UzHRI'>

        • <bdo id='UzHRI'></bdo><ul id='UzHRI'></ul>
            • <legend id='UzHRI'><style id='UzHRI'><dir id='UzHRI'><q id='UzHRI'></q></dir></style></legend>

                  <tbody id='UzHRI'></tbody>

                • <i id='UzHRI'><tr id='UzHRI'><dt id='UzHRI'><q id='UzHRI'><span id='UzHRI'><b id='UzHRI'><form id='UzHRI'><ins id='UzHRI'></ins><ul id='UzHRI'></ul><sub id='UzHRI'></sub></form><legend id='UzHRI'></legend><bdo id='UzHRI'><pre id='UzHRI'><center id='UzHRI'></center></pre></bdo></b><th id='UzHRI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UzHRI'><tfoot id='UzHRI'></tfoot><dl id='UzHRI'><fieldset id='UzHRI'></fieldset></dl></div>

                  本文介紹了無法從 JavaFX 中的 MenuItem 獲取場景的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試根據(jù) menuItem 單擊更改 javafx 階段中的場景.這是我的 sample.fxml:

                  I am trying to change the scene in a javafx stage based on menuItem click. Here is my sample.fxml:

                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <?import java.lang.*?>
                  <?import java.net.*?>
                  <?import javafx.geometry.Insets?>
                  <?import javafx.scene.control.*?>
                  <?import javafx.scene.control.Button?>
                  <?import javafx.scene.control.Label?>
                  <?import javafx.scene.image.*?>
                  <?import javafx.scene.layout.*?>
                  <?import javafx.scene.layout.GridPane?>
                  
                  <AnchorPane prefHeight="-1.0" prefWidth="560.0" styleClass="background" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
                    <children>
                      <MenuBar layoutY="0.0" maxWidth="1.7976931348623157E308" prefWidth="300.0" useSystemMenuBar="false" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="2.0">
                        <menus>
                          <Menu id="manageAccountsMenu" mnemonicParsing="false" onAction="#onManageAccountsMenuActionPerformed" text="Accounts" fx:id="manageAccountsMenu">
                            <items>
                              <MenuItem mnemonicParsing="false" onAction="#onTweetsMenuActionPerformed" text="Manage" fx:id="manageAccountsSubmenuItem" />
                            </items>
                          </Menu>
                          <Menu mnemonicParsing="false" onAction="#onTweetsMenuActionPerformed" text="Tweets" fx:id="tweetsMenuItem" />
                          <Menu mnemonicParsing="false" text="Retweets" />
                        </menus>
                      </MenuBar>
                      <VBox id="VBox" alignment="CENTER" layoutY="24.0" spacing="5.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                        <children>
                          <ScrollPane id="ScrollPane" fitToHeight="true" fitToWidth="true" prefViewportHeight="400.0" prefViewportWidth="300.0">
                            <content>
                              <TableView prefHeight="-1.0" prefWidth="-1.0" tableMenuButtonVisible="true">
                                <columns>
                                  <TableColumn editable="false" prefWidth="75.0" text="SNO" />
                                  <TableColumn prefWidth="200.0" text="Account" />
                                  <TableColumn prefWidth="200.0" text="Status" />
                                  <TableColumn prefWidth="75.0" text="Actions" />
                                </columns>
                              </TableView>
                            </content>
                          </ScrollPane>
                          <Button mnemonicParsing="false" text="Add Account" textAlignment="CENTER">
                            <graphic>
                              <ImageView fitHeight="150.0" fitWidth="200.0" mouseTransparent="true" pickOnBounds="true" preserveRatio="true">
                                <image>
                                  <Image url="@addAccount.png" />
                                </image>
                              </ImageView>
                            </graphic>
                          </Button>
                        </children>
                      </VBox>
                    </children>
                    <stylesheets>
                      <URL value="@darkTheme.css" />
                    </stylesheets>
                  </AnchorPane>
                  

                  這是我的 Controller.java:

                  Here is my Controller.java:

                  package sample;
                  
                  import javafx.event.ActionEvent;
                  import javafx.fxml.FXML;
                  import javafx.fxml.Initializable;
                  import javafx.scene.Node;
                  import javafx.scene.Parent;
                  import javafx.scene.Scene;
                  import javafx.scene.control.MenuItem;
                  import javafx.stage.Stage;
                  
                  import java.net.URL;
                  import java.util.ResourceBundle;
                  
                  public class Controller implements Initializable {
                      @FXML
                      protected void onManageAccountsMenuActionPerformed(ActionEvent event) {
                          System.out.println("Manage Accbtnclick");
                  //        Node node=(Node) event.getSource();
                  //        Stage stage=(Stage) node.getScene().getWindow();
                  //
                  //        Scene scene = new Scene(root);
                  //        stage.setScene(scene);
                  //        stage.show();
                      }
                      @FXML
                      protected void onTweetsMenuActionPerformed(ActionEvent event) {
                          System.out.println("Manage Accbtnclick");
                      Node node= (Node)event.getSource();
                      Stage stage=(Stage) node.getScene().getWindow();
                      Scene scene = Main.screens.get("tweet");
                      stage.setScene(scene);
                      stage.show();
                      }
                  
                      @Override
                      public void initialize(URL url, ResourceBundle resourceBundle) {
                          //To change body of implemented methods use File | Settings | File Templates.
                      }
                  }
                  

                  這是我的 Main.java:

                  Here is my Main.java:

                  package sample;
                  
                  import javafx.application.Application;
                  import javafx.fxml.FXMLLoader;
                  import javafx.geometry.Pos;
                  import javafx.scene.Group;
                  import javafx.scene.Parent;
                  import javafx.scene.Scene;
                  import javafx.scene.control.Label;
                  import javafx.scene.control.ProgressBar;
                  import javafx.scene.control.ProgressIndicator;
                  import javafx.scene.layout.HBox;
                  import javafx.scene.layout.VBox;
                  import javafx.stage.Stage;
                  
                  import java.io.IOException;
                  import java.util.HashMap;
                  
                  public class Main extends Application {
                  
                      public static HashMap<String,Scene> screens=new HashMap<String,Scene>();
                  
                      @Override
                      public void start(Stage stage) {
                          try {
                              Parent accountScreen= FXMLLoader.load(getClass().getResource("sample.fxml"));
                              Parent tweetScreen=FXMLLoader.load(getClass().getResource("tweetform.fxml"));
                              //Parent retweetScreen=FXMLLoader.load(getClass().getResource("retweetform.fxml"));
                              screens.put("account",new Scene(accountScreen));
                              screens.put("tweet",new Scene(tweetScreen));
                              //screens.put("retweet",new Scene(retweetScreen));
                              stage.setTitle("Manage Accounts");
                              stage.setScene(screens.get("account"));
                              stage.show();
                          } catch (IOException e) {
                              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                          }
                  
                      }
                      public static void main(String[] args) {
                          launch(args);
                      }
                  }
                  

                  當我點擊 Accounts Menu 下的 menuItem Manage 時,出現(xiàn)以下異常:

                  When I click on the menuItem Manage under Accounts Menu, I get the following exception:

                      "C:Program FilesJavajdk1.7.0_17injava" -Didea.launcher.port=7541 "-Didea.launcher.bin.path=C:Program Files (x86)JetBrainsIntelliJ IDEA 12.1.4in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.7.0_17jrelibcharsets.jar;C:Program FilesJavajdk1.7.0_17jrelibdeploy.jar;C:Program FilesJavajdk1.7.0_17jrelibjavaws.jar;C:Program FilesJavajdk1.7.0_17jrelibjce.jar;C:Program FilesJavajdk1.7.0_17jrelibjfr.jar;C:Program FilesJavajdk1.7.0_17jrelibjfxrt.jar;C:Program FilesJavajdk1.7.0_17jrelibjsse.jar;C:Program FilesJavajdk1.7.0_17jrelibmanagement-agent.jar;C:Program FilesJavajdk1.7.0_17jrelibplugin.jar;C:Program FilesJavajdk1.7.0_17jrelib
                  esources.jar;C:Program FilesJavajdk1.7.0_17jrelib
                  t.jar;C:Program FilesJavajdk1.7.0_17jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.7.0_17jrelibextdnsns.jar;C:Program FilesJavajdk1.7.0_17jrelibextjaccess.jar;C:Program FilesJavajdk1.7.0_17jrelibextlocaledata.jar;C:Program FilesJavajdk1.7.0_17jrelibextsunec.jar;C:Program FilesJavajdk1.7.0_17jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.7.0_17jrelibextsunmscapi.jar;C:Program FilesJavajdk1.7.0_17jrelibextzipfs.jar;C:Users
                  ahulserverIdeaProjectsDrawingTextoutproductionDrawingText;C:Program Files (x86)JetBrainsIntelliJ IDEA 12.1.4libidea_rt.jar" com.intellij.rt.execution.application.AppMain sample.Main
                  Manage Accbtnclick
                  Manage Accbtnclick
                  java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1440)
                      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
                      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
                      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
                      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
                      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
                      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
                      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
                      at javafx.event.Event.fireEvent(Event.java:171)
                      at javafx.scene.control.MenuItem.fire(MenuItem.java:456)
                      at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1188)
                      at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$6.handle(ContextMenuContent.java:1139)
                      at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$6.handle(ContextMenuContent.java:1137)
                      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
                      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
                      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
                      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
                      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
                      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
                      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
                      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
                      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
                      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
                      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
                      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
                      at javafx.event.Event.fireEvent(Event.java:171)
                      at javafx.scene.Scene$MouseHandler.process(Scene.java:3328)
                      at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)
                      at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)
                      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
                      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)
                      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
                      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
                      at java.security.AccessController.doPrivileged(Native Method)
                      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
                      at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
                      at com.sun.glass.ui.View.notifyMouse(View.java:922)
                      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
                      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
                      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
                      at java.lang.Thread.run(Thread.java:722)
                  Caused by: java.lang.reflect.InvocationTargetException
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                      at java.lang.reflect.Method.invoke(Method.java:601)
                      at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:55)
                      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                      at java.lang.reflect.Method.invoke(Method.java:601)
                      at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:269)
                      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
                      ... 40 more
                  Caused by: java.lang.ClassCastException: javafx.scene.control.MenuItem cannot be cast to javafx.scene.Node
                      at sample.Controller.onTweetsMenuActionPerformed(Controller.java:29)
                      ... 50 more
                  

                  那么如何從菜單項單擊事件處理程序中獲取包含階段/場景?

                  So how do I get the containing stage/scene from the menu Item clicked event handler?

                  編輯

                  Node node= (Node)event.getSource();
                  

                  在 controller.java 中是第 29 行,這會產(chǎn)生問題.

                  in controller.java is line number 29 which is giving problems.

                  推薦答案

                  你真正的錯誤顯示在堆棧跟蹤的倒數(shù)第二行:

                  Your real error is shown in the second to last line of the stack trace:

                  Caused by: java.lang.ClassCastException: javafx.scene.control.MenuItem cannot be cast to javafx.scene.Node
                      at sample.Controller.onTweetsMenuActionPerformed(Controller.java:29)
                  

                  此錯誤指的是控制器中的以下行:

                  This error is referring to the following line from your controller:

                  Node node= (Node)event.getSource();
                  

                  查看 JavaFX API 文檔,MenuItem 和 Menu 都不是 Node 的子類.http://docs.oracle.com/javafx/2/api/javafx/場景/控制/MenuItem.htmlhttp://docs.oracle.com/javafx/2/api/javafx/場景/控制/Menu.html

                  Looking at the JavaFX API Docs, neither MenuItem nor Menu are subclasses of Node. http://docs.oracle.com/javafx/2/api/javafx/scene/control/MenuItem.html http://docs.oracle.com/javafx/2/api/javafx/scene/control/Menu.html

                  我建議將源作為對象獲取,然后在繼續(xù)之前檢查其類型.另外,我在使用 getSource() 方法時遇到了問題;getTarget() 方法對我來說效果更好.不管怎樣,你仍然需要一種方法來進入舞臺.

                  I would suggest grabbing the source as an Object, then checking its type before continuing. Also, I ran into problems using the getSource() method; the getTarget() method worked better for me. Either way, you still need a way to get the to the Stage.

                  為此,您可能希望在 FXML 中使用 fx:id 標簽,而不是 id 標簽.這將允許您將 FXML 元素直接注入到您的控制器中.例如,您可以通過將 MenuBar 元素注入控制器來從 MenuBar(它是 Node 的子類)中獲取舞臺.

                  To do this, you might want to use the fx:id tag in your FXML instead of the id tag. This will allow you to inject the FXML elements directly into your controller. For example, you could grab the Stage from the MenuBar (which is a subclass of Node) by injecting the MenuBar element into your controller.

                  在 FXML 中:

                  <MenuBar fx:id="myMenuBar" layoutY="0.0" maxWidth="1.7976931348623157E308" prefWidth="300.0" useSystemMenuBar="false" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="2.0">
                  

                  在控制器中:

                  public class Controller implements Initializable {
                      @FXML MenuBar myMenuBar;
                      ...
                      @FXML
                      protected void onTweetsMenuActionPerformed(ActionEvent event) {
                          System.out.println("Manage Accbtnclick");
                          Stage stage = (Stage) myMenuBar.getScene().getWindow();
                          Scene scene = Main.screens.get("tweet");
                          stage.setScene(scene);
                          stage.show();
                      }
                      ...
                  }
                  

                  您可能需要在此處進行一些調(diào)整,但希望對您有所幫助.

                  You may need to do a bit of tweaking here, but hopefully it helps.

                  這篇關(guān)于無法從 JavaFX 中的 MenuItem 獲取場景的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)

                    <small id='Cz6xX'></small><noframes id='Cz6xX'>

                    <i id='Cz6xX'><tr id='Cz6xX'><dt id='Cz6xX'><q id='Cz6xX'><span id='Cz6xX'><b id='Cz6xX'><form id='Cz6xX'><ins id='Cz6xX'></ins><ul id='Cz6xX'></ul><sub id='Cz6xX'></sub></form><legend id='Cz6xX'></legend><bdo id='Cz6xX'><pre id='Cz6xX'><center id='Cz6xX'></center></pre></bdo></b><th id='Cz6xX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Cz6xX'><tfoot id='Cz6xX'></tfoot><dl id='Cz6xX'><fieldset id='Cz6xX'></fieldset></dl></div>

                        <tbody id='Cz6xX'></tbody>
                      <tfoot id='Cz6xX'></tfoot>

                          <bdo id='Cz6xX'></bdo><ul id='Cz6xX'></ul>
                          • <legend id='Cz6xX'><style id='Cz6xX'><dir id='Cz6xX'><q id='Cz6xX'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 99热首页| 盗摄精品av一区二区三区 | 一区二区三区在线 | 欧美视频在线看 | 91精品国产91久久久久久 | 欧美在线二区 | 中文字幕日韩欧美 | 日韩影院在线观看 | 精品视频在线一区 | 久久久久国产精品一区二区 | 久久88 | 久久久免费 | 伊人网站视频 | 国产乱码精品一品二品 | 中文二区 | 黑人精品xxx一区一二区 | 三区在线观看 | 91国在线观看 | 欧美日韩一区二区三区不卡视频 | 91深夜福利视频 | 免费a大片 | 成人精品视频 | 日日摸夜夜添夜夜添特色大片 | 精品久久电影 | 国产高清精品一区二区三区 | 中文字幕一级毛片 | 国产伦一区二区三区 | 欧美一级欧美一级在线播放 | 欧产日产国产精品视频 | av在线成人| 免费国产视频 | 国产午夜精品一区二区三区嫩草 | 欧美日韩视频在线 | 亚洲一区二区三区四区五区中文 | 91精品国产高清一区二区三区 | 精品一区二区三区中文字幕 | 中文字幕蜜臀av | 综合二区| 精品96久久久久久中文字幕无 | 99久久久久久久 | 精品在线一区 |