JavaFX应用程序中的Combobox不会下拉

时间:2014-10-16 21:39:00

标签: macos javafx fullscreen

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

这是我的代码。

主文件:

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框有效。

1 个答案:

答案 0 :(得分: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