2016-05-29 5 views
2

こんにちは私はJavaFXに奇妙な問題があります。私はコントローラを使用しています。シーンビルダがあなたに提供します。 問題はありません。メニューバーのメニューはクリックされません。 これは私のコントローラです:JavaFXカンタン使用onAction

/** 
* Sample Skeleton for 'Main.fxml' Controller Class 
*/ 

package com.agronaut022.gui_changer.GUI.Scenes.Main; 

import java.io.File; 
import java.io.IOException; 
import java.io.UnsupportedEncodingException; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.net.URLDecoder; 
import java.security.CodeSource; 
import java.util.ResourceBundle; 

import org.apache.commons.configuration.ConfigurationException; 

import com.agronaut022.gui_changer.GUI.classes.MessageBox; 
import com.agronaut022.gui_changer.etc.Config; 

import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.fxml.FXML; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ListView; 
import javafx.scene.control.Menu; 
import javafx.scene.control.MenuBar; 
import javafx.scene.control.ProgressBar; 
import javafx.scene.layout.Pane; 
import javafx.stage.Stage; 
import junit.framework.Test; 

public class MainController 
`enter code here`{ 

@FXML 
private ResourceBundle resources; 

@FXML 
private URL location; 

@FXML 
private ListView<?> ListView; 

@FXML 
private Button Change_Button; 

@FXML 
private Menu Help; 

@FXML 
private Menu about; 

@FXML 
private MenuBar MenuBar; 

@FXML 
private Pane pane; 

@FXML 
private ProgressBar ProgressBar; 

@FXML 
void initialize() { 
assert Help != null : "fx:id=\"Help\" was not injected: check your FXML file 'Main.fxml'."; 
    assert ListView != null : "fx:id=\"ListView\" was not injected: check your FXML file 'Main.fxml'."; 
    assert Change_Button != null : "fx:id=\"Change_Button\" was not injected: check your FXML file 'Main.fxml'."; 
    assert about != null : "fx:id=\"about\" was not injected: check your FXML file 'Main.fxml'."; 
    assert MenuBar != null : "fx:id=\"MenuBar\" was not injected: check your FXML file 'Main.fxml'."; 
    assert pane != null : "fx:id=\"pane\" was not injected: check your FXML file 'Main.fxml'."; 
    assert ProgressBar != null : "fx:id=\"ProgressBar\" was not injected: check your FXML file 'Main.fxml'."; 

Help.setOnAction(new EventHandler<ActionEvent>() 
{ 
    @Override 
    public void handle(ActionEvent event) 
    { 
    System.out.println("ABout"); 
    Parent root; 
    try 
    { 
     root = FXMLLoader.load(getClass().getClassLoader().getResource("com/agronaut022/gui_changer/GUI/Scenes/About/About.fxml"), 
      resources); 
     Stage stage = new Stage(); 
     stage.setTitle("About"); 
     stage.setScene(new Scene(root, 600, 425)); 
     stage.show(); 

    } catch (IOException e) 
    { 
     e.printStackTrace(); 
    } 


    } 

}); 

/* Change_Button.setOnAction(new EventHandler<ActionEvent>() 
{ 

    @Override 
    public void handle(ActionEvent event) 
    { 
    Parent root; 
    try 
    { 
     root = FXMLLoader.load(getClass().getClassLoader().getResource("com/agronaut022/gui_changer/GUI/Scenes/About/About.fxml"), 
      resources); 
     Stage stage = new Stage(); 
     stage.setTitle("About"); 
     stage.setScene(new Scene(root, 600, 425)); 
     stage.show(); 

    } catch (IOException e) 
    { 
     e.printStackTrace(); 
    } 


    } 
}); */ 

} 
} 

そして、私のFXMLファイルは、私はすでに切り抜いたメニュー項目が、同じ結果を使用してみました、私はすべてのエラーを得ていない午前のprogrammが正常に起動し、 この

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.control.*?> 
<?import java.lang.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.layout.AnchorPane?> 

<Pane fx:id="pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-  Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.agronaut022.gui_changer.GUI.Scenes.Main.MainController"> 
<children> 
     <MenuBar id="MenuBar" fx:id="MenuBar" layoutY="2.0" prefHeight="25.0" prefWidth="350.0"> 
    <menus> 
     <Menu mnemonicParsing="false" text="File"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="Import GUI" /> 
       <MenuItem mnemonicParsing="false" text="Change Starmade Directory" /> 
       <MenuItem mnemonicParsing="false" text="Create Details" /> 
      </items></Menu> 
     <Menu mnemonicParsing="false" text="Backup" /> 
     <Menu mnemonicParsing="false" text="Settings" /> 
     <Menu fx:id="about" mnemonicParsing="false" text="About" /> 
     <Menu fx:id="Help" mnemonicParsing="false" text="Help" /> 
    </menus> 
    </MenuBar> 
    <ListView fx:id="ListView" layoutX="12.0" layoutY="43.0" prefHeight="450.0" prefWidth="326.0" /> 
    <ProgressBar fx:id="ProgressBar" layoutX="12.0" layoutY="499.0" prefHeight="35.0" prefWidth="326.0" progress="0.0" /> 
    <Button id="Change_Button" fx:id="Change_Button" layoutX="12.0" layoutY="540.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="326.0" text="Button" /> 
    </children> 
</Pane> 

です。

答えて

2

少なくともMenuitemのないMenuはイベントを発生させないためです。

既にあなたのような質問があります。ここに解決策があります https://stackoverflow.com/a/19006643/5702956

+0

ありがとう、私はこれについて知っていませんでした、私はWindowsFormsのようになるだろうと思った。 – Agronaut022

関連する問題