2013-02-01 52 views
0

我想用包含項目的組合框設計一個應用程序。並選擇我想給用戶自動填寫建議。但是在做這個組合框時沒有解決。我附上了這些文件。組合框無法在javafx中解析

Ademo.fxml

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

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

<AnchorPane prefHeight="268.0" prefWidth="290.0" xmlns:fx="http://javafx.com/fxml" fx:controller="v.C_hgj"> 
    <!-- TODO Add Nodes --> 
    <children> 
    <ComboBox layoutX="110.0" layoutY="98.0" fx:id="fruitCombo" prefWidth="90.0" promptText="choose"> 
     <items> 
     <FXCollections fx:factory="observableArrayList"> 
      <String fx:value="Apple" /> 
      <String fx:value="orange" /> 
      <String fx:value="mango" /> 
      <String fx:value="banana" /> 
      <String fx:value="guava" /> 
      <String fx:value="water melon" /> 
     </FXCollections> 
     </items> 
    </ComboBox> 
    </children> 
</AnchorPane> 

V_hgj.java

package v; 

    import java.util.logging.Level; 
    import java.util.logging.Logger; 

    import javafx.application.Application; 
    import javafx.fxml.FXMLLoader; 
    import javafx.scene.Scene; 
    import javafx.scene.layout.AnchorPane; 
    import javafx.stage.Stage; 

    public class V_hgj extends Application{ 


     public static void main(String[] args) { 
      launch(V_hgj.class, (java.lang.String[])null); 

     } 

     @Override 
     public void start(Stage primaryStage) throws Exception { 
      try 
      { 

       //loading .fxml file 

       AnchorPane ap=FXMLLoader.load(V_hgj.class.getResource("Ademo.fxml")); 
       Scene sc=new Scene(ap); 
       primaryStage.setScene(sc); 
       primaryStage.setTitle("Product"); 


       //getting external .css file 
       // primaryStage.getScene().getStylesheets().add("file:/~/helper/gui.css"); 
       primaryStage.show(); 
      } 
      catch(Exception ex) 
      { 
       Logger.getLogger(V_product.class.getName()).log(Level.SEVERE, null, ex); 
      } 
     } 

    } 

C_hgj.java

package v; 

import java.net.URL; 
import java.util.ResourceBundle; 

import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 

public class C_hgj implements Initializable{ 

    @FXML 
    private ComboBox fruitCombo; 
    public static void main(String[] args) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void initialize(URL location, ResourceBundle resources) { 
     // TODO Auto-generated method stub 
     assert fruitCombo!=null : "reset botton not injected"; 

    } 

} 

請幫忙....

+0

請提供確切的異常消息。 – Puce

+1

你有哪個Java/JavaFX版本? – Puce

+0

java版本1.7和javafx2.0 –

回答

1

在課堂C_hgj(請按Java代碼慣例)你需要d導入javafx.scene.control.ComboBox

+0

...那麼它也會給我錯誤。錯誤:「導入javafx.scene.control.ComboBox無法解析」 –