The event method that I'm talking about is changeBackgroundScreen. The button is being covered by a background image in one of my css file. At first I thought it was the background blocking the button from being interact with. I took the background image off and it still didn't work. Now I have no clue.
Here is a portion of the FXML File For you to focus on:
<HBox alignment="CENTER" spacing="200">
<children>
<Button fx:id="optionButton1" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground1"/>
<Button fx:id="optionButton2" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground2"/>
<Button fx:id="optionButton3" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground3"/>
</children>
</HBox>
Here is the entire FXML File if you're interested:
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.*?>
<?import java.net.URL?>
<StackPane fx:id="Optionmenu" id="BlueBackground1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="millionairetriviagame.OptionscreenController">
<stylesheets>
<URL value="#BackgroundImages.css" />
</stylesheets>
<stylesheets>
<URL value="#ButtonLayout.css"/>
</stylesheets>
<children>
<VBox alignment="TOP_CENTER" spacing="20">
<ImageView>
<image>
<Image url="#ImageFiles/MillionaireLogo1.png"/>
</image>
</ImageView>
<Label text="Click to Change the Background Color" style="-fx-font-style: Italic;" textFill="white">
<font>
<javafx.scene.text.Font name="sans-serif" size="20" />
</font>
</Label>
<HBox alignment="CENTER" spacing="200">
<children>
<Button fx:id="optionButton1" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground1"/>
<Button fx:id="optionButton2" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground2"/>
<Button fx:id="optionButton3" onAction="#changeBackgroundScreen" prefWidth="80" prefHeight="50" id="SmallBlueBackground3"/>
</children>
</HBox>
</VBox>
<HBox alignment="BOTTOM_RIGHT" spacing="10" >
<children>
<Button fx:id="backToMain" prefWidth="200" prefHeight="30" onAction="#goToTheMainMenu" text="Back to the Main Menu" styleClass="ButtonLayout">
<shape>
<javafx.scene.shape.Rectangle width="200" height="30" arcHeight="30" arcWidth="30" />
</shape>
</Button>
</children>
</HBox>
</children>
</StackPane>
Here is my controller Class
package millionairetriviagame;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class OptionscreenController implements Initializable, ControllingScreens
{
private ScreenNavigator controller;
private MediaPlayer optionMenuPlayer;
#FXML private Button backToMain;
private BooleanProperty isDisabled;
#FXML private StackPane Optionmenu;
#FXML private Button optionButton1;
#FXML private Button optionButton2;
#FXML private Button optionButton3;
#FXML private StackPane mainMenu;
#Override
public void initialize(URL url, ResourceBundle rb)
{
configureProperties();
playSong();
}
private void configureProperties()
{
isDisabled = new SimpleBooleanProperty();
backToMain.disableProperty().bind(isDisabled);
}
#Override
public void setScreenParent(ScreenNavigator parentScreen)
{
controller = parentScreen;
}
private void playSong()
{
Media optionIntroTheme = new Media(getClass().getResource("/millionairetriviagame/AudioFiles/OptionMenuMusic.mp3").toExternalForm());
optionMenuPlayer = new MediaPlayer(optionIntroTheme);
optionMenuPlayer.setAutoPlay(true);
optionMenuPlayer.setVolume(0.1);
optionMenuPlayer.setCycleCount(MediaPlayer.INDEFINITE);
}
#FXML private void changeBackgroundScreen(ActionEvent event)
{
try
{
FXMLLoader myLoader = new FXMLLoader(getClass().getResource(MillionaireTriviaGame.MAIN));
myLoader.load();
mainMenu = myLoader.getRoot();
}
catch (IOException ex)
{
Logger.getLogger(OptionscreenController.class.getName()).log(Level.SEVERE, null, ex);
}
if(optionButton2.isPressed())
{
mainMenu.setId("BlueBackground2");
Optionmenu.setId("BlueBackground2");
}
}
#FXML private void goToTheMainMenu(ActionEvent event)
{
isDisabled.setValue(true);
optionMenuPlayer.stop();
controller.loadScreen(MillionaireTriviaGame.MAINSCREENID, MillionaireTriviaGame.MAIN);
controller.setScreen(MillionaireTriviaGame.MAINSCREENID);
}
}
Here is my CSS File if you need to look at it as well.
#BlueBackground1
{
-fx-background-image: url("/millionairetriviagame/ImageFiles/BlueBackgroundColor.jpg");
}
#BlueBackground2
{
-fx-background-image: url("/millionairetriviagame/ImageFiles/BlueBackgroundColor2.jpg");
}
#SmallBlueBackground1
{
-fx-background-image: url("/millionairetriviagame/ImageFiles/BlueBackgroundColor.jpg");
-fx-background-repeat: stretch;
-fx-background-size: 80 50;
-fx-background-position: center center;
-fx-background-insets: 0, 0, 0, 0;
}
#SmallBlueBackground2
{
-fx-background-image: url("/millionairetriviagame/ImageFiles/BlueBackgroundColor2.jpg");
-fx-background-repeat: stretch;
-fx-background-size: 80 50;
-fx-background-position: center center;
-fx-background-insets: 0, 0, 0, 0;
}
#SmallBlueBackground3
{
-fx-background-image: url("/millionairetriviagame/ImageFiles/BlueBackgroundColor3.jpg");
-fx-background-repeat: stretch;
-fx-background-size: 80 50;
-fx-background-position: center center;
-fx-background-insets: 0, 0, 0, 0;
}
Here is a visual
Problem
The problem is with your layout. You have a StackPane with VBox (containing the buttons which fire the changeBackgroundScreen methods) and on top of that you have a HBox (with a single button, aligned to bottom right).
At the first glance everything might just look cool. But, remember VBox and HBox are layouts which fill their parent. So, even if you can't see, the HBox lies on top of your buttons in the VBox blocking all the interactions.
Solution
A more complex solution would be to use something other than a StackPane because I don't really see the need of it. But, since you already have the layout, lets go with something which needs little tweaking to the layout.
A very simple solution would be to move the HBox into the VBox. This way, there is no blocking layer. But, since you want the button to stick to the bottom-right of the scene, we will use a Region in between the children of the VBox and set the VGrow as Always. This will push the newly added HBox to the bottom of the scene and make it stick there no matter what your scene size is.
Complete FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.*?>
<?import java.net.URL?>
<StackPane id="BlueBackground1" fx:id="Optionmenu" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40" fx:controller="millionairetriviagame.OptionscreenController">
<stylesheets>
<URL value="#BackgroundImages.css" />
</stylesheets>
<stylesheets>
<URL value="#ButtonLayout.css" />
</stylesheets>
<children>
<VBox alignment="TOP_CENTER" spacing="20">
<ImageView>
<image>
<Image url="#ImageFiles/MillionaireLogo1.png" />
</image>
</ImageView>
<Label style="-fx-font-style: Italic;" text="Click to Change the Background Color" textFill="white">
<font>
<javafx.scene.text.Font name="sans-serif" size="20" />
</font>
</Label>
<HBox alignment="CENTER" spacing="200">
<children>
<Button id="SmallBlueBackground1" fx:id="optionButton1" onAction="#changeBackgroundScreen" prefHeight="50" prefWidth="80" />
<Button id="SmallBlueBackground2" fx:id="optionButton2" onAction="#changeBackgroundScreen" prefHeight="50" prefWidth="80" />
<Button id="SmallBlueBackground3" fx:id="optionButton3" onAction="#changeBackgroundScreen" prefHeight="50" prefWidth="80" />
</children>
</HBox>
<Region prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
<HBox alignment="BOTTOM_RIGHT" spacing="10">
<children>
<Button fx:id="backToMain" onAction="#goToTheMainMenu" prefHeight="30" prefWidth="200" styleClass="ButtonLayout" text="Back to the Main Menu">
<shape>
<javafx.scene.shape.Rectangle arcHeight="30" arcWidth="30" height="30" width="200" />
</shape>
</Button>
</children>
</HBox>
</VBox>
</children>
</StackPane>
Related
This is my main inside application package:
package application;
import java.net.URL;
import javax.swing.JOptionPane;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import model.Model;
public class Main extends Application {
Parent root;
Scene scene;
#Override
public void start(Stage primaryStage) {
try {
URL url = getClass().getResource("/view/AddCustomer.fxml");
root = FXMLLoader.load(url);
scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(e -> {
int save = JOptionPane.showConfirmDialog(null, "Do you want to save changes in the product table?");
if (save == 0) {
Model.getInstance().SaveCustomers();
Model.getInstance().SaveSessions();
Model.getInstance().SaveAdministrators();
Model.getInstance().SaveCoachs();
}
System.exit(0);
});
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
This is my addCustomerController inside controller package:
package controller;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
public class AddCustomerController {
#FXML
private Button cancelMemberButton;
#FXML
private Pane customerPane;
#FXML
private RadioButton dailyMemberType;
#FXML
private TextField memberDiscountField;
#FXML
private RadioButton memberFemaleButton;
#FXML
private TextField memberIdField;
#FXML
private RadioButton memberMaleButton;
#FXML
private TextField memberMobileField;
#FXML
private TextField memberNameField;
#FXML
private TextField memberNationalityField;
#FXML
private RadioButton monthlyMemberType;
#FXML
private Button saveMemberButton;
#FXML
private RadioButton yearlyMemberType;
#FXML
void cancelButtonClick(ActionEvent event) {
}
#FXML
void saveButtonClick(ActionEvent event) {
}
}
This is the FXML file inside view package(Its called AddCustomer.fxml):
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.ToggleButtonGroup?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<Pane fx:id="customerPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="532.0" prefWidth="789.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.AddCustomerController">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="258.0" layoutY="34.0" prefHeight="41.0" prefWidth="274.0" text="Add Customer" textFill="#860b0b">
<font>
<Font name="Arial" size="37.0" />
</font>
</Label>
<Separator layoutY="98.0" prefHeight="1.0" prefWidth="789.0" style="-fx-background-color: #860b0b;">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Separator>
<Label layoutX="27.0" layoutY="144.0" prefHeight="23.0" prefWidth="103.0" text="Member ID" />
<Label layoutX="27.0" layoutY="195.0" prefHeight="23.0" prefWidth="103.0" text="Name" />
<Label layoutX="27.0" layoutY="243.0" prefHeight="23.0" prefWidth="103.0" text="Mobile" />
<Label layoutX="27.0" layoutY="296.0" prefHeight="23.0" prefWidth="103.0" text="Nationality" />
<Label layoutX="27.0" layoutY="345.0" prefHeight="23.0" prefWidth="103.0" text="Gender" />
<Label layoutX="27.0" layoutY="394.0" prefHeight="23.0" prefWidth="103.0" text="MemberShip Type" />
<Label layoutX="27.0" layoutY="440.0" prefHeight="23.0" prefWidth="103.0" text="Discount" />
<TextField fx:id="memberIdField" layoutX="246.0" layoutY="143.0" prefHeight="30.0" prefWidth="486.0" />
<TextField fx:id="memberNameField" layoutX="246.0" layoutY="194.0" prefHeight="25.0" prefWidth="486.0" />
<TextField fx:id="memberMobileField" layoutX="246.0" layoutY="242.0" prefHeight="25.0" prefWidth="486.0" />
<TextField fx:id="memberNationality" layoutX="246.0" layoutY="295.0" prefHeight="25.0" prefWidth="486.0" />
<RadioButton fx:id="memberMaleButton" layoutX="341.0" layoutY="348.0" mnemonicParsing="false" text="Male" />
<RadioButton fx:id="memberFemaleButton" layoutX="412.0" layoutY="348.0" mnemonicParsing="false" text="Female" />
<RadioButton fx:id="dailyMemberType" layoutX="341.0" layoutY="397.0" mnemonicParsing="false" text="Daily" />
<RadioButton fx:id="monthlyMemberType" layoutX="412.0" layoutY="397.0" mnemonicParsing="false" text="Monthly" />
<RadioButton fx:id="yearlyMemberType" layoutX="499.0" layoutY="397.0" mnemonicParsing="false" text="Yearly" />
<TextField fx:id="discountField" editable="false" layoutX="246.0" layoutY="439.0" prefHeight="25.0" prefWidth="486.0" />
<Button fx:id="saveMemberButton" layoutX="246.0" layoutY="482.0" mnemonicParsing="false" onAction="#saveButtonClick" prefHeight="30.0" prefWidth="164.0" text="Save" />
<Button fx:id="cancelMemberButton" layoutX="499.0" layoutY="482.0" mnemonicParsing="false" onAction="#cancelButtonClick" prefHeight="30.0" prefWidth="164.0" text="Cancel" />
<ToggleButtonGroup layoutX="130.0" layoutY="170.0" selectionType="SINGLE" />
</children>
</Pane>
This is the error I get when run my main:
javafx.fxml.LoadException:
/C:/Users/ADMIN/eclipse-workspace/Project_V2_V2/bin/view/AddCustomer.fxml
at javafx.fxml#19/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
at javafx.fxml#19/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2949)
at javafx.fxml#19/javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2793)
at javafx.fxml#19/javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2758)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2624)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3331)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3287)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3255)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3227)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3203)
at javafx.fxml#19/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3196)
at Project_V2_V2/application.Main.start(Main.java:22)
at javafx.graphics#19/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics#19/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics#19/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics#19/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics#19/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.ToggleButtonGroup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:3017)
at javafx.fxml#19/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:3006)
at javafx.fxml#19/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2947)
... 20 more
I searched online for problems, i found all of the issues that has been offered online are not similar to mine at least from what i understood. I fixed some things that were in my code. However, it still did not solve the issue for me. Please i need help fixing this issue.
You are using Gluons com.gluonhq.charm.glisten.control.ToggleButtonGroup from their mobile tooling. Do you really want to do that? Maybe using the standard JavaFX ToggleGroup would be sufficient. If you really want to use Gluons lib then you have to add this implementation 'com.gluonhq:charm-glisten:6.2.2' to your dependencies. But note, that glisten is a proprietary offering with a different license than JavaFX.
Hi I'd like add to control "Spinner" integers between 1 to 24. I write my function and i added to fxml file but display exception (JavaFX 11).
Normally while I build window display spinner with default value "7" i can also change int from 1 to 24 but with each click display this exception.
Summarizing,
addChangeVIEW.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="305.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.controller.addChangeController">
<children>
<Button fx:id="addChangeButton" graphicTextGap="8.0" layoutX="413.0" layoutY="110.0" mnemonicParsing="false" prefHeight="85.0" prefWidth="128.0" text="ADD CHANGE" textAlignment="CENTER" textFill="#e50a0a" textOverrun="LEADING_WORD_ELLIPSIS" />
<DatePicker fx:id="dateChangePicker" layoutX="23.0" layoutY="138.0" />
<Label fx:id="descDatePicker" layoutX="70.0" layoutY="100.0" prefHeight="18.0" prefWidth="89.0" text="Date Change">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="fromHourLabel" layoutX="215.0" layoutY="99.0" text="From Hour" />
<Label fx:id="toHourLabel" layoutX="311.0" layoutY="99.0" text="To Hour" />
<Label fx:id="statusLabel" layoutX="83.0" layoutY="216.0" prefHeight="33.0" prefWidth="258.0" text="WAIT FOR ADD CHANGE" textFill="#14f004">
<font>
<Font name="Arial" size="18.0" />
</font>
</Label>
<Spinner fx:id="fromHourSpinner" layoutX="214.0" layoutY="137.0" onMouseClicked="#spinnersAction" prefHeight="26.0" prefWidth="58.0" />
<Spinner fx:id="toHourSpinner" accessibleText="1" layoutX="303.0" layoutY="137.0" onMouseClicked="#spinnersAction" prefHeight="26.0" prefWidth="58.0" />
</children>
</AnchorPane>
addChangeController
package com.controller;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import java.net.URL;
import java.util.ResourceBundle;
public class addChangeController implements Initializable {
#FXML
private Spinner<Integer> fromHourSpinner;
#FXML
private Spinner<Integer> toHourSpinner;
SpinnerValueFactory<Integer> spinner = new SpinnerValueFactory.IntegerSpinnerValueFactory(1,24,7);
#FXML
public void spinnersAction(ActionEvent event){
//fromHourSpinner.setValueFactory(spinner);
}
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
fromHourSpinner.setValueFactory(spinner);
}
}
Init
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
Process finished with exit code 0
As i have same problem, So here is the solution i found
Just need to rearrange the code a little bit like this..
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
SpinnerValueFactory<Integer> spinner =new SpinnerValueFactory.IntegerSpinnerValueFactory(1,24,7);
fromHourSpinner.setValueFactory(spinner);
toHourSpinner.setValueFactory(spinner);
}
We're currently developing a social media platform as a project at school (to be handed in in 2 weeks), and we've ran into some issues when trying to get the UI to scale with the application window. Currently it works as supposed when previewing it in SceneBuilder (see the first link) , but it seems to be stuck in the upper left corner when running the actual application via IntelliJ IDEA. I've also linked a screenshot of how it's actual behavior is (second link).
This is how the scaling should work, and as you can see it does work when i use SceneBuilder's preview function.
This is how the scaling is working when we run the app, which isn't scaling at all.
At the moment we're just trying to understand whats wrong, therefore our only focus is the 'discover page' of the platform (you access the page from the events page). So i will post the fxml code for the discover page as well as the events controller. Bare in mind this is my first ever post on here, so if there's anything else that could help you help us just tell me and i'll get it uploaded! Here is a screenshot of all the classes in our project, if there's any other class that would be helpful if i post just say the word :)
All classes in the project.
FXML for the Discover page:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane fx:id="borderPaneDiscover" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="JavaFX.DiscoverController">
<center>
<AnchorPane prefHeight="200.0" prefWidth="900.0" BorderPane.alignment="CENTER">
<children>
<TableView fx:id="tableViewDiscover" layoutY="62.0" onMouseClicked="#showDetails" prefHeight="331.0" prefWidth="900.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="65.0">
<columns>
<TableColumn fx:id="eventNameColumnDiscover" minWidth="180.0" prefWidth="75.0" text="Event name" />
<TableColumn fx:id="eventLocationColumnDiscover" minWidth="180.0" prefWidth="75.0" text="Event location" />
<TableColumn fx:id="eventDateColumnDiscover" minWidth="180.0" prefWidth="75.0" text="Event date" />
<TableColumn fx:id="eventCategoryColumnCategory" minWidth="180.0" prefWidth="75.0" text="Event category" />
<TableColumn fx:id="eventCreatorColumnDiscover" minWidth="180.0" prefWidth="75.0" text="Event Creator" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<Label alignment="CENTER" prefHeight="18.0" prefWidth="190.0" text="Choose category of the event:" textAlignment="CENTER" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<ChoiceBox fx:id="choiceBoxDiscover" layoutX="375.0" layoutY="20.0" prefHeight="30.0" prefWidth="150.0" AnchorPane.leftAnchor="375.0" AnchorPane.rightAnchor="375.0" AnchorPane.topAnchor="20.0" />
<Button fx:id="buttonGo" layoutX="505.0" mnemonicParsing="false" onAction="#showTableDiscover" prefHeight="30.0" prefWidth="55.0" style="-fx-background-color: #313131; -fx-text-fill: #FFF; -fx-font-weight: BOLD;" text="Go" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="20.0">
<effect>
<DropShadow />
</effect>
</Button>
</children>
</AnchorPane>
</center>
<bottom>
<AnchorPane prefHeight="145.0" prefWidth="900.0" BorderPane.alignment="CENTER">
<children>
<TextArea fx:id="textAreaDescription" editable="false" layoutX="60.0" layoutY="20.0" prefHeight="120.0" prefWidth="250.0" wrapText="true" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="60.0" AnchorPane.rightAnchor="590.0" AnchorPane.topAnchor="20.0" />
<TextArea fx:id="textAreaParticipants" editable="false" layoutX="360.0" layoutY="20.0" prefHeight="120.0" prefWidth="250.0" wrapText="true" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="290.0" AnchorPane.topAnchor="20.0" />
<Button fx:id="attendButton" layoutX="660.0" layoutY="45.0" mnemonicParsing="false" onAction="#attendEvent" prefHeight="50.0" prefWidth="100.0" style="-fx-background-color: #313131; -fx-text-fill: #ffffff; -fx-font-weight: BOLD;" text="Attend" AnchorPane.bottomAnchor="50.0" AnchorPane.rightAnchor="40.0" AnchorPane.topAnchor="45.0">
<effect>
<DropShadow />
</effect>
</Button>
<Text layoutX="65.0" layoutY="15.0" strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-size: 14; -fx-font-weight: BOLD;" text="Description:" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="2.0">
<font>
<Font name="Segoe UI Symbol" size="14.0" />
</font>
</Text>
<Text layoutX="365.0" layoutY="15.0" strokeType="OUTSIDE" strokeWidth="0.0" style="-fx-font-size: 14; -fx-font-weight: BOLD;" text="Participants:" AnchorPane.rightAnchor="457.0" AnchorPane.topAnchor="2.0">
<font>
<Font name="Segoe UI Symbol" size="14.0" />
</font>
</Text>
</children>
</AnchorPane>
</bottom>
<top>
<AnchorPane prefHeight="16.0" prefWidth="900.0" BorderPane.alignment="CENTER">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="315.0" prefHeight="54.0" prefWidth="289.0" text="Discover events" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Label>
<Button alignment="CENTER_RIGHT" layoutX="833.0" layoutY="10.0" mnemonicParsing="false" onAction="#BackToEvents" prefHeight="34.0" prefWidth="55.0" style="-fx-background-color: #313131; -fx-text-fill: #FFF; -fx-font-size: 14; -fx-font-weight: BOLD;" text="Back" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="10.0">
<font>
<Font name="Segoe UI Symbol" size="20.0" />
</font>
<effect>
<DropShadow />
</effect>
</Button>
</children>
</AnchorPane>
</top>
</BorderPane>
FXML for the events page:
package JavaFX;
import javafx.collections.*;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import java.io.IOException;
public class EventsController {
private ObservableList<String> usersChoice = FXCollections.observableArrayList("My events(attended/to attend and created)", "Discover(search by category and attend)", "Create event");
#FXML
private BorderPane eventsPane;
#FXML
private ChoiceBox <String> choicebox;
#FXML
private Label labelOfUserChoice;
#FXML
private void initialize(){
choicebox.setItems(usersChoice);
//choicebox.getSelectionModel().selectedItemProperty().addListener(changeListener);
}
#FXML
private void changeLabel() throws IOException/*, InterruptedException*/{
switch (choicebox.getValue()) {
//ask sokol about it
case ("My events(attended/to attend and created)"):
labelOfUserChoice.setText("You have chosen: " + choicebox.getValue());
choicebox.setDisable(true);
//TimeUnit.SECONDS.sleep(5);
loadMyEvents();
break;
case ("Discover(search by category and attend)"):
labelOfUserChoice.setText("You have chosen: " + choicebox.getValue());
choicebox.setDisable(true);
//TimeUnit.SECONDS.sleep(1);
loadDiscover();
break;
case ("Create event"):
labelOfUserChoice.setText("You have chosen: " + choicebox.getValue());
//TimeUnit.SECONDS.sleep(1);
loadCreateEvent();
break;
default:
System.out.println("YOU'VE BETTER LEARN HOW TO USE JFX!");
}
}
#FXML
private void goToMainMenu(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/resources/mainMenu.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
#FXML
private void goToProfile(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/resources/profile.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
#FXML
private void goToFriends(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/resources/friendsPage.fxml"));
loader.setLocation(getClass().getResource("/resources/friendsPage.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
#FXML
private void goToChat(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/chatclient/FXMLDocument.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
private void loadMyEvents() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/resources/myEvents.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
private void loadDiscover() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/resources/discover.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
private void loadCreateEvent() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/resources/createEvent.fxml"));
BorderPane pane = loader.load();
eventsPane.getChildren().setAll(pane);
}
}
So far i've read probably all the posts in here that are issues remotely like ours, but none of them have seemed to work. I haven't been able to find a post stating the exact same issue as ours, where the preview window in SceneBuilder works as supposed and the program when we run it doesn't. I hope someone can help us out, thanks in advance! :)
I'm new to JavaFX , i'm trying to create a transparent scene and stage the problem is when I add nodes like images and labels , the scene is no longer transparent
this is my code
package application;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
public class Main extends Application {
private double xOffset = 0;
private double yOffset = 0;
public void start(Stage primaryStage) throws Exception {
try{
Parent root ;
root = FXMLLoader.load(getClass().getResource("/View/Authentification.fxml"));
primaryStage.initStyle(StageStyle.TRANSPARENT);
Scene scene = new Scene(root);
scene.setFill(null);
root.setOnMousePressed(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
primaryStage.setX(event.getScreenX() - xOffset);
primaryStage.setY(event.getScreenY() - yOffset);
}
});
primaryStage.setScene(scene);
primaryStage.show();}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
and this is my xml code :
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane layoutY="94.0" prefHeight="417.0" prefWidth="363.0" style="-fx-background-color: #3D4966;"/>
<AnchorPane layoutX="-1.0" prefHeight="82.0" prefWidth="363.0" style="-fx-background-color: #3D4966;">
<children>
<Label layoutX="280.0" layoutY="70.0" text="Fermer" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<ImageView layoutX="288.0" layoutY="22.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../images/Shutdown.png" />
</image>
</ImageView>
<Label layoutX="146.0" layoutY="61.0" prefHeight="17.0" prefWidth="92.0" text="crée un compte" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
<ImageView layoutX="167.0" layoutY="21.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../images/Add_User.png" />
</image>
</ImageView>
<ImageView layoutX="50.0" layoutY="21.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../images/User.png" />
</image>
</ImageView>
<Label layoutX="50.0" layoutY="62.0" text="Ce connecter" textFill="#eee5e5">
<font>
<Font name="System Bold" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>
</AnchorPane>
i tried a lot of other codes but nothing seems to work
these are some screenshots with nodes
without nodes
If you create one or more controls (specifically, any instance of Control or a subclass), the default stylesheet is applied to the scene. This sets the background color of the root of the scene to a non-transparent "very light grey" (basically 26.4% lighter than #ececec).
(Specifically, the default stylesheet contains the following:
.root {
/***************************************************************************
* *
* The main color palette from which the rest of the colors are derived. *
* *
**************************************************************************/
/* A light grey that is the base color for objects. Instead of using
* -fx-base directly, the sections in this file will typically use -fx-color.
*/
-fx-base: #ececec;
/* A very light grey used for the background of windows. See also
* -fx-text-background-color, which should be used as the -fx-text-fill
* value for text painted on top of backgrounds colored with -fx-background.
*/
-fx-background: derive(-fx-base,26.4%);
/* ... */
-fx-background-color: -fx-background;
}
The source for the current version of the default stylesheet (at the time of writing) can be found at http://hg.openjdk.java.net/openjfx/9/rt/file/c734b008e3e8/modules/javafx.controls/src/main/resources/com/sun/javafx/scene/control/skin/modena/modena.css).
So you need to make the root of the scene transparent too.
You can do this using inline CSS, either in the FXML:
<AnchorPane style="-fx-background-color: transparent ;" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
or in Java:
Parent root ;
root = FXMLLoader.load(getClass().getResource("/View/Authentification.fxml"));
root.setStyle("-fx-background-color: transparent ;");
or you can do it in an external style sheet:
.root {
-fx-background-color: transparent ;
}
Getting LoadExeption evertime i try to run this code.
the code ran fine the first time but after that i just keep getting this error.
Its just a simple login page with not much coding what so ever.
Main class below
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root=FXMLLoader.load(getClass().getResource("/application/Login.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args); // tried changing this to string[0] didnt work
}
}
Main controller class below i wanted to add more sql stuff to this but i keep getting the same error.
In this i am just trying to change
package application;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import javafx.fxml.FXML;
public class MainController {
#FXML
private Label LblStatus;
#FXML
private TextField TxtUsername;
#FXML
private TextField TxtPassword;
public void Login(ActionEvent event)
{
LblStatus.setText("Login sucsess");
}
}
login page
All of this was created using scene builder and youtube.
so i basically have no idea why i am getting this error.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="400.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.MainController">
<!-- TODO Add Nodes -->
<children>
<Pane prefHeight="400.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<TitledPane animated="false" layoutX="0.0" layoutY="0.0" prefHeight="400.0000999999975" prefWidth="500.0" text="LOGIN FORM" textAlignment="CENTER" wrapText="false">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextField fx:id="TxtUsername" layoutX="227.0" layoutY="129.0" prefWidth="200.0" promptText="Enter Username" />
<Label layoutX="129.0" layoutY="129.0" prefWidth="98.0" text="USERNAME:">
<font>
<Font size="15.0" fx:id="x1" />
</font>
</Label>
<Label font="$x1" layoutX="129.0" layoutY="183.0" prefWidth="98.0" text="PASSWORD:" />
<Button font="$x1" layoutX="224.0" layoutY="225.0" mnemonicParsing="false" onAction="#Login" text="LOGIN" />
<PasswordField fx:id="TxtPassword" layoutX="224.0" layoutY="183.0" prefWidth="200.0" promptText="Enter Password" />
<Label id="Status" fx:id="LblStatus" layoutX="259.0" layoutY="69.0" text="Status">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
<font>
<Font name="Arial Black" size="15.0" />
</font>
</TitledPane>
</children>
</Pane>
</children>
</AnchorPane>
You have the wrong imports in your controller. Replace
import java.awt.Label;
with
import javafx.scene.control.Label ;
etc...