0

I have a mixed up codes where I am building a program using Scene Builder with Splash Screen. I built a button on a TitledPane on top of Anchor Pane which is root. I set the fx:id and when I run, I cannot click anything. Not even a tab from titled pane or any buttons. Funny thing is, I can traverse with tab key and click space to actually mouse click it. What is going on and what should I do fix this?

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.FadeTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import javafx.util.Duration;

/** * * @author heecheonpark */ public class FXMLDocumentController implements Initializable {

@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);
    }
}

}

<?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>
user7693152
  • 9
  • 1
  • 5

1 Answers1

0

It's because you set the property mouseTransparent="true" at your TitledPane.

In JavaFX the MouseTransparent property make any Node and all his children ignore any mouse interaction, that's why you can't click the buttons. Just remove it and it should work.

Node - MouseTransparentProperty

Baptiste Beauvais
  • 1,886
  • 1
  • 12
  • 19