2

I am trying to achieve the same interface which I have developed using Scene Builder. But for some reason, CSS is not loading. This is what I am supposed to get! enter image description here This is what I am getting! enter image description here

Parent root;

    try {

    root = FXMLLoader.load(getClass().getResource("/path../path../TutorControlPanel.fxml"));

    Stage stage = new Stage();

    stage.setTitle("Tutor Control Panel");

    stage.setScene(new Scene(root, 950, 750));

    stage.show();

         } catch (IOException ex) {
             Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
                       }
                } else {
                      System.out.println("user not found");

                        }

                        }

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

XML Starts Here!

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

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

<VBox fx:id="root" prefHeight="750.0" prefWidth="950.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">


   <children>
      <HBox prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #353f40;">
         <children>
            <ImageView>
               <image>
                  <Image url="@../../../Images/Accuranture.png" />
               </image>
            </ImageView>
            <GridPane fx:id="gridView" prefHeight="150.0" prefWidth="688.0">
              <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
              </columnConstraints>
              <rowConstraints>
                <RowConstraints maxHeight="71.0" minHeight="10.0" prefHeight="36.0" vgrow="SOMETIMES" />
                <RowConstraints maxHeight="120.0" minHeight="10.0" prefHeight="114.0" vgrow="SOMETIMES" />
              </rowConstraints>
               <children>
                  <Button fx:id="recordButton" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="70.0" prefWidth="70.0" stylesheets="@Style.css" textFill="WHITE" GridPane.rowIndex="1">
                     <GridPane.margin>
                        <Insets bottom="15.0" left="15.0" right="15.0" top="10.0" />
                     </GridPane.margin>
                     <padding>
                        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
                     </padding>
                     <tooltip>
                        <Tooltip text="Screencast Lessons">
                           <font>
                              <Font size="16.0" />
                           </font>
                        </Tooltip>
                     </tooltip>
                  </Button>
                  <Button fx:id="stopButton" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="70.0" prefWidth="70.0" stylesheets="@Style.css" GridPane.rowIndex="1">
                     <GridPane.margin>
                        <Insets bottom="100.0" left="100.0" right="100.0" top="100.0" />
                     </GridPane.margin>
                     <padding>
                        <Insets top="10.0" />
                     </padding>
                  </Button>
                  <Label text="Record" textFill="WHITE" GridPane.rowIndex="1">
                     <GridPane.margin>
                        <Insets bottom="100.0" left="20.0" right="90.0" top="200.0" />
                     </GridPane.margin>
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="30.0" layoutY="141.0" text="Stop" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets bottom="5.0" left="115.0" right="40.0" top="255.0" />
                     </GridPane.margin>
                  </Label>
                  <MenuButton fx:id="settingsButton" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="70.0" prefWidth="70.0" stylesheets="@Style.css" GridPane.rowIndex="1">
                    <items>
                      <MenuItem fx:id="qualitySettings" mnemonicParsing="false" text="Quality" />
                      <MenuItem fx:id="videoSettings" mnemonicParsing="false" text="Speed" />
                    </items>
                     <GridPane.margin>
                        <Insets bottom="14.0" left="190.0" right="100.0" top="15.0" />
                     </GridPane.margin>
                     <opaqueInsets>
                        <Insets />
                     </opaqueInsets>
                  </MenuButton>
                  <Label layoutX="125.0" layoutY="141.0" text="Settings" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="190.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <Button fx:id="lessoncategory" layoutX="110.0" layoutY="65.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="55.0" prefWidth="70.0" stylesheets="@Style.css">
                     <padding>
                        <Insets top="10.0" />
                     </padding>
                     <GridPane.margin>
                        <Insets left="310.0" top="155.0" />
                     </GridPane.margin>
                  </Button>
                  <Label layoutX="200.0" layoutY="141.0" text="Create Category" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="285.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <MenuButton fx:id="serverUpload" layoutX="200.0" layoutY="66.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="70.0" prefWidth="70.0" stylesheets="@Style.css">
                     <items>
                        <MenuItem fx:id="startUpload" mnemonicParsing="false" text="Quality" />
                        <MenuItem fx:id="stopUpload" mnemonicParsing="false" text="Speed" />
                     </items>
                     <opaqueInsets>
                        <Insets />
                     </opaqueInsets>
                     <GridPane.margin>
                        <Insets left="435.0" top="145.0" />
                     </GridPane.margin>
                  </MenuButton>
                  <Label layoutX="295.0" layoutY="141.0" text="Server Uploads" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="420.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <Button fx:id="timer" layoutX="25.0" layoutY="63.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="70.0" prefWidth="70.0" stylesheets="@Style.css">
                     <padding>
                        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
                     </padding>
                     <tooltip>
                        <Tooltip text="Screencast Lessons">
                           <font>
                              <Font size="16.0" />
                           </font>
                        </Tooltip>
                     </tooltip>
                     <GridPane.margin>
                        <Insets left="550.0" top="145.0" />
                     </GridPane.margin>
                  </Button>
                  <Label fx:id="timerHours" layoutX="430.0" layoutY="141.0" text="00 : " textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="550.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <Label fx:id="timerMinutes" layoutX="560.0" layoutY="141.0" text=" 00 : " textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="575.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <Label fx:id="timerSeconds" layoutX="585.0" layoutY="141.0" text="  00 " textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="600.0" top="250.0" />
                     </GridPane.margin>
                  </Label>
                  <Label layoutX="560.0" layoutY="141.0" text="Timer" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="565.0" top="220.0" />
                     </GridPane.margin>
                  </Label>
                  <Button fx:id="logOut" mnemonicParsing="false" prefHeight="26.0" prefWidth="25.0" stylesheets="@Style.css">
                     <GridPane.margin>
                        <Insets left="650.0" />
                     </GridPane.margin>
                  </Button>
                  <Label layoutX="30.0" layoutY="144.0" text="Log Out" textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="590.0" />
                     </GridPane.margin>
                  </Label>
                  <Label layoutX="30.0" layoutY="144.0" text="Welcome Back " textFill="WHITE">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets />
                     </GridPane.margin>
                  </Label>
                  <Label fx:id="uNameLabel" layoutX="10.0" layoutY="19.0" text="User" textFill="LAWNGREEN">
                     <font>
                        <Font name="System Bold" size="14.0" />
                     </font>
                     <GridPane.margin>
                        <Insets left="120.0" />
                     </GridPane.margin>
                  </Label>
               </children>
            </GridPane>
         </children>
      </HBox>
      <SplitPane dividerPositions="0.32293986636971045" style="-fx-background-color: ;" VBox.vgrow="ALWAYS">
         <items>
            <ListView prefHeight="200.0" prefWidth="200.0" />
            <Pane prefHeight="200.0" prefWidth="200.0">
               <children>
                  <MediaView fitHeight="500.0" fitWidth="575.0" layoutX="15.0" layoutY="24.0" />
               </children>
            </Pane>
         </items>
      </SplitPane>
   </children>
</VBox>
3
  • 1
    Just letting you know guys that I am trying to load this windows from another window Commented Mar 29, 2016 at 21:35
  • 1
    Can you post the FXML contents of the file TutorControlPanel.fxml? I don't see anything in your supplied Java code that loads a CSS file, so I'm assuming it must be in there. Commented Mar 29, 2016 at 22:12
  • @Cypher XML added mate. Commented Mar 29, 2016 at 22:16

1 Answer 1

1

I had to make 2 changes in order to get intended results

1.Firstly, Bring all images into the folder where Style.css is

2.secondly, Add these lines of code:

String css = this.getClass().getResource("Style.css").toExternalForm(); scene.getStylesheets().add(css);

     try {

    Parent root=FXMLLoader.load(getClass().getResource("/eLearning/UserInterface/TutorControlPanel.fxml"));
    Scene scene = new Scene(root);

      String css = this.getClass().getResource("Style.css").toExternalForm();
                        scene.getStylesheets().add(css);
                        Stage stage = new Stage();

                        stage.setTitle("Tutor Control Panel");

                        stage.setScene(scene);
                        stage.show();

                    } catch (IOException ex) {
                        Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    System.out.println("user not found");

                }

            }

        } catch (SQLException ex) {
            Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.