2014-10-16 78 views
1

我有一些javafx代码,我想以全屏模式运行。它包含一个组合框。当我以全屏模式运行应用程序时,下拉弹出窗口不会出现,当我点击下拉框时。我该如何解决它。JavaFX应用程序中的Combobox不会下拉

这是我的代码。

主文件:

package javafxapplication1; 

import java.io.IOException; 
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.StackPane; 
import javafx.stage.Stage; 

/** 
* 
* @author movingstories 
*/ 
public class JavaFXApplication1 extends Application { 

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

      primaryStage.setFullScreen(true); 

      StackPane root = new StackPane(); 
      root.getChildren().add(FXMLLoader.load(this.getClass().getResource("FXML.fxml"))); 


      Scene scene = new Scene(root, 300, 250); 

      primaryStage.setTitle("Hello World!"); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 

     } catch (IOException ex) { 
      Logger.getLogger(JavaFXApplication1.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 

} 

形式FXML:

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

<?import javafx.geometry.*?> 
<?import javafx.scene.text.*?> 
<?import java.lang.*?> 
<?import java.net.*?> 
<?import java.util.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<AnchorPane id="AnchorPane" fx:id="anchorPane" prefHeight="768.0" prefWidth="1024.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication1.FXMLController"> 
    <stylesheets> 
     <URL value="@common.css" /> 
     <URL value="@participantdetails.css" /> 
    </stylesheets> 
    <children> 
     <Button fx:id="nextBtn" layoutX="822.0" layoutY="620.0" mnemonicParsing="false" text="Next" /> 
     <GridPane fx:id="gridPane" layoutX="440.0" layoutY="314.0"> 
     <columnConstraints> 
      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" /> 
      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" /> 
      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" /> 
     </columnConstraints> 
     <rowConstraints> 
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" /> 
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" /> 
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" /> 
      <RowConstraints minHeight="10.0" vgrow="SOMETIMES" /> 
     </rowConstraints> 
     <children> 
      <Label layoutX="442.0" layoutY="349.0" text="Email" GridPane.rowIndex="1" /> 
      <TextField fx:id="nameField" layoutX="482.0" layoutY="314.0" GridPane.columnIndex="1" /> 
      <Label layoutX="443.0" layoutY="318.0" text="Name" /> 
      <ComboBox fx:id="genderField" layoutX="481.0" layoutY="376.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" /> 
      <ComboBox fx:id="ageField" layoutX="481.0" layoutY="408.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" /> 
      <Label layoutX="443.0" layoutY="412.0" text="Age" GridPane.rowIndex="3" /> 
      <TextField fx:id="emailField" layoutX="482.0" layoutY="345.0" GridPane.columnIndex="1" GridPane.rowIndex="1" /> 
      <Label layoutX="635.0" layoutY="412.0" text="yrs" GridPane.columnIndex="2" GridPane.rowIndex="3" /> 
      <Label layoutX="440.0" layoutY="380.0" text="Gender" GridPane.rowIndex="2" /> 
     </children> 
     </GridPane> 
    </children> 
</AnchorPane> 

和FXML控制器

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package javafxapplication1; 

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.ComboBox; 

/** 
* FXML Controller class 
* 
* @author movingstories 
*/ 
public class FXMLController implements Initializable { 

    @FXML 
    private ComboBox genderField; 

    /** 
    * Initializes the controller class. 
    */ 
    @Override 
    public void initialize(URL url, ResourceBundle rb) { 
     // TODO 

     genderField.getItems().add("Male"); 
     genderField.getItems().add("Female"); 
    }  

} 

主文件包含行primaryStage.setFullScreen(true);。如果我评论这一行,我可以看到combox盒子的工作原理。

+0

这看起来像一个错误。我看到了同样的效果(你不需要任何复杂的东西来看它,只是一个全屏窗口中的“ComboBox”)。你有什么JDK版本和你在哪个平台上运行? – 2014-10-17 00:35:28

回答

2

我在Mac OS X 10.9.5上测试过;我在JDK 1.7.0_67,JDK 1.8.0_20和JDK 1.8.0_25中看到了相同的效果。它似乎在JDK 1.8.0_40 ea b07(early access)中得到修复。

我用这个简单的测试案例:

import javafx.application.Application; 
import javafx.beans.value.ChangeListener; 
import javafx.beans.value.ObservableValue; 
import javafx.collections.FXCollections; 
import javafx.scene.Scene; 
import javafx.scene.control.ComboBox; 
import javafx.scene.layout.BorderPane; 
import javafx.stage.Stage; 

public class FullScreenComboBoxTest extends Application { 

    @Override 
    public void start(final Stage primaryStage) { 

      ComboBox<String> combo = new ComboBox<String>(FXCollections.observableArrayList("Male", "Female")); 
      combo.showingProperty().addListener(new ChangeListener<Boolean>() { 
       @Override 
       public void changed(ObservableValue<? extends Boolean> obs, Boolean wasShowing, Boolean isShowing) { 
        System.out.println("Showing: "+isShowing); 
       } 
      }); 

      BorderPane root = new BorderPane(); 
      root.setTop(combo); 

      Scene scene = new Scene(root, 300, 250); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 
      primaryStage.setFullScreen(true); 

    } 

    public static void main(String[] args) { 
     launch(args); 
    } 

} 

更新:

这实际上适用于任何弹出窗口(事实上,任何辅助窗口在所有)在全屏模式下在Mac OS X 。所以上下文菜单,工具提示等也不起作用。这是RT-38338

+0

是的,实际上所有的输入控件都很奇怪。光标不出现在文本字段中,所有关注字段的夜灯都会丢失。我会测试更新40.只是出于好奇,任何想法是什么是在更新40中的修复?谢谢! – Ankit 2014-10-20 20:04:05

+0

据我了解,在版本40之前,他们推出了自己的全屏实施。这是因为他们想要支持10.7之前的OS X版本,而这些版本没有原生的全屏支持。由于这些版本的OS X在Java 1.8中不受支持,因此它们现在使用本地全屏支持。 (同样,这是我的理解,不能保证我是正确的。) – 2014-10-20 20:12:43