Javafx和fxml按钮无法点击

时间:2017-10-16 05:36:41

标签: button javafx click fxml traversal

我有一个混合代码,我正在使用带有Splash Screen的Scene Builder构建程序。我在Anchor Pane顶部的TitledPane上构建了一个按钮,它是root。我设置了fx:id,当我运行时,我无法点击任何内容。甚至不是标题窗格或任何按钮的标签。有趣的是,我可以使用tab键遍历并单击空格以实际鼠标单击它。发生了什么事,我应该怎么做才能解决这个问题?

@FXML
private Label label;

@FXML
private AnchorPane root;

@FXML
private TitledPane tPane;

@FXML
private AnchorPane aPane1;

@FXML
private ListView listView;

@FXML
private Button addBtn;

@FXML
private void addButtonAction(ActionEvent event) {
            FileChooser fc = new FileChooser();
            File selectedFile = fc.showOpenDialog(null);
            if (selectedFile != null){
                listView.getItems().add(selectedFile.getName());  
            }
            else{
                System.out.println("The file is not valid.");
            }
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    if (!MajorProject.isSplashLoaded){
    loadSplashScreen();

    }
}    
private void loadSplashScreen(){
    try {
        AnchorPane aPane = FXMLLoader.load(getClass().getResource("SplashFXML.fxml"));
        root.getChildren().addAll(aPane);
        FadeTransition fadeIn = new FadeTransition(Duration.seconds(3), aPane);
        fadeIn.setFromValue(0);
        fadeIn.setToValue(1);
        fadeIn.setCycleCount(1);

        FadeTransition fadeOut = new FadeTransition(Duration.seconds(3), aPane);
        fadeOut.setFromValue(1);
        fadeOut.setToValue(0);
        fadeOut.setCycleCount(1);

        fadeIn.play();

        fadeIn.setOnFinished((e) -> {
        fadeOut.play();
        MajorProject.isSplashLoaded = true;
        });

        fadeOut.setOnFinished((e) -> {
            try { 
                Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));


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

        });

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

/ **  *  * @author heecheonpark  * /     公共类FXMLDocumentController实现Initializable {

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

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

<AnchorPane fx:id="root" focusTraversable="true" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="majorproject.FXMLDocumentController">
   <children>
      <ListView fx:id="listView" layoutX="302.0" layoutY="53.0" prefHeight="304.0" prefWidth="248.0">
         <effect>
            <Glow />
         </effect>
      </ListView>
      <TitledPane fx:id="tPane" animated="false" mouseTransparent="true" text="Product">
         <content>
            <AnchorPane fx:id="aPane1">
               <children>
                  <Button layoutY="131.0" mnemonicParsing="true" text="Button" />
                  <Button fx:id="addBtn" layoutY="104.0" mnemonicParsing="false" onAction="#addButtonAction" text="Add" />
               </children>
            </AnchorPane>
         </content>
      </TitledPane>
   </children>
</AnchorPane>

}

UPDATE DWCUST t1
SET GENDER = (SELECT NEW_VALUE FROM GENDERSPELLING t2
              WHERE t1.GENDER = t2.INVALID_VALUE)
WHERE GENDER NOT IN ('M', 'F');

1 个答案:

答案 0 :(得分:0)

这是因为您在mouseTransparent="true"设置了属性TitledPane

在JavaFX中,MouseTransparent属性使任何Node 及其所有孩子忽略任何鼠标交互,这就是您无法单击按钮的原因。只需删除它就可以了。

Node - MouseTransparentProperty