/r/JavaFX

Photograph via snooOG

JavaFX is an open source, next generation client application platform for desktop, mobile and embedded systems.

Useful resources (Full list)

Rules

  1. No NSFW/NSFL content
  2. No service requests/offers
  3. Must be JavaFX related
  4. No politics

Related subreddits

Other communities

/r/JavaFX

6,810 Subscribers

0

I need help with using a method

I have a JavaFx project where they gave me many classes with methods i have to use, but there's one method that gives me problems all the time, its the method registerUser() its in the class Acount.class

the code is this one :

package javafxmlapplication;

import java.io.IOException;

import model.*;

import java.io.File;

import java.net.URL;

import java.time.LocalDate;

import java.util.Date;

import java.util.ResourceBundle;

import javafx.beans.property.BooleanProperty;

import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.fxml.Initializable;

import javafx.scene.control.Button;

import javafx.scene.control.CheckBox;

import javafx.scene.control.Label;

import javafx.scene.control.PasswordField;

import javafx.scene.control.TextField;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.AnchorPane;

import javafx.stage.FileChooser;

import model.Acount;

import model.User;

import model.AcountDAOException;

import model.AcountDAO;

import model.*;

/**

*

* @author jsoler

*/

public class FXMLDocumentController implements Initializable {

@FXML

private Button login_btn;

@FXML

private Button login_createAccount;

@FXML

private AnchorPane login_form;

@FXML

private PasswordField login_password;

@FXML

private CheckBox login_selectShowPassword;

@FXML

private TextField login_username;

@FXML

private PasswordField signup_cPassword;

@FXML

private Button signup_btn;

@FXML

private Button signupimg_btn;

@FXML

private TextField signup_email;

@FXML

private AnchorPane signup_form;

@FXML

private ImageView signup_image;

@FXML

private Button signup_loginAccount;

@FXML

private TextField signup_name;

@FXML

private PasswordField signup_password;

@FXML

private TextField signup_username;

@FXML

private TextField signup_surname;

private Acount nuevaCuenta;

public void register() throws AcountDAOException, IOException {

//Date date = new Date();

alertMessage alert = new alertMessage();

if (signup_name.getText().isEmpty() || signup_email.getText().isEmpty() || signup_username.getText().isEmpty()

|| signup_password.getText().isEmpty() || signup_cPassword.getText().isEmpty() || signup_surname.getText().isEmpty()) {

alert.errorMessage("All fields are necessary to be filled");

} else if (signup_password.getText().equals(signup_cPassword.getText()) == false) {

// CHECK IF THE VALUE OF PASSWORD FIELDS IS EQUAL TO CONFIRM PASSWORD

alert.errorMessage("Password does not match");

}//else{ nuevaCuenta.registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), image, date.getTime());

Acount nuevacuenta = Acount.getInstance();

Date date = new Date();

boolean result;

result = nuevacuenta.getInstance().registerUser(signup_name.getText(), signup_surname.getText(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), LocalDate.MAX)registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getImage(), date.getTime());

}

public void ButtonImage(ActionEvent event) {

FileChooser fc = new FileChooser();

File selectedFile = fc.showOpenDialog(null);

if (selectedFile != null) {

Image image = new Image(selectedFile.getPath());

signup_image.setImage(image);

} else {

Image defaultIMG = new Image("/avatars/default.png");

signup_image.setImage(defaultIMG);

}

}

//=========================================================

// you must initialize here all related with the object

@Override

public void initialize(URL url, ResourceBundle rb) {

// TODO

//Date date = new Date();

//if (true == registerUser(signup_name.getText(), signup_surname.getText().isEmpty(), signup_email.getText(), signup_username.getText(), signup_password.getText(), signup_image.getId(), date.getTime()))

}

}

12 Comments
2024/05/12
12:02 UTC

2

Touch Events on Popup only work when mouse cursor is on top of it

I have a JavaFX app running on Raspberry Pi OS and I'm using touchscreen to control it, but I also have a mouse connected to the computer for different purposes. In my application, I'm using Popups and my problem is that if the mouse cursor is outside of the area of the popup then the Touch doesn't work on that popup. I cannot click on anything using touchscreen, nothing is working. But once I move the mouse cursor in the area where the popup is, suddenly all touch controls start working. Then, if I move cursor out of the popup area, nothing works again. The cursor simply has to always be in the area of popup for the touch controls to work. This is true also if the mouse cursor is invisible. Have anyone faced this issue? Is there any simple solution? I have tried calling "requestFocus()" on the root Pane of the popup right after the "show()" call, but that didn't help.

Thank you

0 Comments
2024/05/10
05:17 UTC

0

Problema con la conf/Integración

Alguien que controle de JavaFX a ver si me puede echar un cable, tengo un proyecto en NetBeans de javafx y se ve que no lo he integrado/configurado bien, al principio ejecutaba el proyecto según iba haciendo cosas para ir probando y no daba problema, hoy me ha dado por ejecutar el Jar y me daba un error de que no había mainclass, despues me fui al proyecto y en propiedades seleccione la main y ahora no me va ni el jar ni al ejecutarlo en netbens AYUDA.

0 Comments
2024/05/08
10:03 UTC

1

how to use MFXTableView and MFXTableColumn?

a normal Column would have a parameters <S,T> but in MFXTableColumn, it only has <T>, how can i use it? also there's no setCellValueFactory method in MFXTableColumn, so how can I use it? I can't find any related posts or links regarding my concern. thank you

2 Comments
2024/05/08
08:18 UTC

2

How to make confetti effect

How do i make it rain confetti when I open the window?

2 Comments
2024/05/07
09:26 UTC

1

gridpane growing infinitely vertically

my code creates a gridpane that reloads every second i was wondering why the gridpane continues to grow downwards on each reload, ive likely missed something simple but would love to know how to fix it.
File 1

package Fallin.gui;

/**
* This class is just to start up the GUI without requiring any VM options.
*
*/
public class RunGame {

public static void main(String[] args) {
GameGUI.main(args);
}
}

FILE 2

<?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.\*?> <?import javafx.scene.layout.\*?> <BorderPane prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Fallin.gui.Controller" maxHeight="800" maxWidth="800"> <padding> <Insets bottom="15.0" left="15.0" right="15.0" top="15.0" /> </padding> <center> <GridPane fx:id="gridPane" prefHeight="800.0" prefWidth="800.0" BorderPane.alignment="CENTER" maxHeight="800" maxWidth="800"> <columnConstraints> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="9"/> <ColumnConstraints percentWidth="10"/> </columnConstraints> <rowConstraints> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> <RowConstraints percentHeight="10"/> </rowConstraints> </GridPane> </center> </BorderPane> FILE 3

package Fallin.gui;

import Fallin.engine.Cell;
import Fallin.engine.GameEngine;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.TilePane;
import javafx.scene.text.Text;
import javafx.util.Duration;

import java.util.Arrays;

public class Controller {
u/FXML
private GridPane gridPane;
TilePane buttontileup = new TilePane();
TilePane buttontiledown = new TilePane();
TilePane buttontileleft = new TilePane();
TilePane buttontileright = new TilePane();

GameEngine engine;

u/FXML
public void initialize() {
engine = new GameEngine(10);
Timeline timeline = new Timeline(
new KeyFrame(Duration.seconds(1.0), e -> {
updateGui();
})
);
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();

}

private void updateGui() {
//Clear old GUI grid pane
gridPane.getChildren().clear();

Button up = new Button("up");
Button down = new Button("down");
Button left = new Button("left");
Button right = new Button("right");

Label upl = new Label("up");
Label downl = new Label("down");
Label leftl = new Label("left");
Label rightl = new Label("right");
EventHandler<ActionEvent> eventup = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
engine.playerlocationchage(0,-1);
System.out.println("up");
System.out.println(Arrays.toString(engine.getplayerlocation()));

}

};
EventHandler<ActionEvent> eventdown = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
engine.playerlocationchage(0,1);
System.out.println("down");
System.out.println(Arrays.toString(engine.getplayerlocation()));

}
};
EventHandler<ActionEvent> eventleft = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
engine.playerlocationchage(-1,0);
System.out.println("left");
System.out.println(Arrays.toString(engine.getplayerlocation()));

}
};
EventHandler<ActionEvent> eventright = new EventHandler<ActionEvent>() {
public void handle(ActionEvent e)
{
engine.playerlocationchage(1,0);
System.out.println("right");
System.out.println(Arrays.toString(engine.getplayerlocation()));

}
};
up.setOnAction(eventup);
down.setOnAction(eventdown);
left.setOnAction(eventleft);
right.setOnAction(eventright);

buttontileup.getChildren().add(up);
buttontileup.getChildren().add(upl);
buttontiledown.getChildren().add(down);
buttontiledown.getChildren().add(downl);
buttontileleft.getChildren().add(left);
buttontileleft.getChildren().add(leftl);
buttontileright.getChildren().add(right);
buttontileright.getChildren().add(rightl);

gridPane.getChildren().clear();
System.out.println(1);
engine.reloadmap();
//Loop through map board and add each cell into grid pane
for(int i = 0; i < engine.getSize(); i++) {
for (int j = 0; j < engine.getSize(); j++) {
Cell cell = engine.getMap()[i][j];
System.out.println(cell);
System.out.println(engine.getSize());
gridPane.add(cell, j, i);
GridPane.setHgrow(cell, Priority.NEVER);
GridPane.setVgrow(cell, Priority.NEVER);
}
}
gridPane.add(buttontileup,1,10);
GridPane.setHgrow(buttontileup, Priority.NEVER);
GridPane.setVgrow(buttontileup, Priority.NEVER);
gridPane.add(buttontiledown,3,10);
GridPane.setHgrow(buttontiledown, Priority.NEVER);
GridPane.setVgrow(buttontiledown, Priority.NEVER);
gridPane.add(buttontileleft,6,10);
GridPane.setHgrow(buttontileleft, Priority.NEVER);
GridPane.setVgrow(buttontileleft, Priority.NEVER);
gridPane.add(buttontileright,8,10);
GridPane.setHgrow(buttontileright, Priority.NEVER);
GridPane.setVgrow(buttontileright, Priority.NEVER);
gridPane.setGridLinesVisible(true);
}

}

FILE 4

package Fallin.gui;

import Fallin.engine.GameEngine;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
* GUI for the Maze Runner Game.
*
* NOTE: Do NOT run this class directly in IntelliJ - run 'RunGame' instead.
*/
public class GameGUI extends Application {

u/Override
public void start(Stage primaryStage) throws Exception {
BorderPane root = FXMLLoader.load(getClass().getResource("game_gui.fxml"));

primaryStage.setScene(new Scene(root, 1000, 1000));
primaryStage.setTitle("Fallin Game");
primaryStage.show();
}

/** In IntelliJ, do NOT run this method. Run 'RunGame.main()' instead. */
public static void main(String[] args) {
launch(args);
}
}
FILE 5

package Fallin.engine;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.TilePane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class GameEngine {

/**
* An example board to store the current game state.
*
* Note: depending on your game, you might want to change this from 'int' to String or something?
*/
private Cell[][] map;
int playerx = 0;
int playery = 9;
List<Integer> xlist = new ArrayList<Integer>();
List<Integer> ylist = new ArrayList<Integer>();
int enemies;
int treasure;
int traps;
int mapsize;
/**
* Creates a square game board.
*
* u/param size the width and height.
*/
public GameEngine(int size) {
mapsize=size;
Random rand = new Random();
map = new Cell[size][size];
int enemies = 5;
int treasure = 8;
int traps = 5;
for(int i = 0; i<(enemies+treasure+traps);i++){
boolean b=true;
while(b) {
int x=0;
int y=0;
x= rand.nextInt(10);
y= rand.nextInt(10);
int[] pair = {x,y};
if (xlist.size()>0){
if(paircheck(x,y,xlist,ylist) >=0) {
continue;
}}
xlist.add(pair[0]);
ylist.add(pair[1]);
b=false;
}
}
reloadmap();
}
public void reloadmap(){
System.out.println("reload");
for (int i = 0; i < mapsize; i++) {
for (int j = 0; j < mapsize; j++) {
Cell cell = new Cell();
int pairnumber = paircheck(i, j, xlist, ylist);
if (pairnumber > -1) {
if (pairnumber < enemies) {
Image image = new Image("File:src/main/resources/enemy.png");
cell.getChildren().add(new ImageView(image));
} else if (pairnumber < (enemies + treasure)) {
Image image = new Image("File:src/main/resources/treasuresmall.png");
cell.getChildren().add(new ImageView(image));
} else {
Image image = new Image("File:src/main/resources/trapsmall.png");
cell.getChildren().add(new ImageView(image));
}

} else if (i == playery) {
if (j == playerx) {
Image image = new Image("File:src/main/resources/player.png");
cell.getChildren().add(new ImageView(image));
}
} else {
Text text = new Text(i + "," + j);
if (i + j == 9) {
if (i == 0) {
text.setFill(Paint.valueOf("#C70039"));
} else if (j == 0) {
text.setFill(Paint.valueOf("#C70039"));
}
} else if ((i + j) % 2 == 0) {
text.setFill(Paint.valueOf("#7baaa4"));
} else {
text.setFill(Color.BLACK);
}
cell.getChildren().add(text);

}
map[i][j] = cell;
if ((i + j) % 2 == 0) {
map[i][j].setStyle("-fx-background-color: #7baaa4");
} else {
map[i][j].setStyle("-fx-background-color: #000000");
}
if (i + j == 9) {
if (i == 0) {
map[i][j].setStyle("-fx-background-color: #C70039");
} else if (j == 0) {
map[i][j].setStyle("-fx-background-color: #C70039");
}
}
}
}
}

/**
* The size of the current game.
*
* u/return this is both the width and the height.
*/
public int getSize() {
return map.length;
}

/**
* The map of the current game.
*
* u/return the map, which is a 2d array.
*/
public Cell[][] getMap() {
return map;
}

/**
* Plays a text-based game
*/
public static void main(String[] args) {
GameEngine engine = new GameEngine(10);
System.out.printf("The size of map is %d * %d\n", engine.getSize(), engine.getSize());
}
public int paircheck(int x, int y, List<Integer> xlist, List<Integer> ylist){
int[] pair ={x,y};
if(x+y==9){
if(x==0){
return -2;
}
if(y==0){
return -3;
}
}
for(int i =0;i<xlist.size();i++){
int[] pairtocheck = {xlist.get(i),ylist.get(i)};
if (pairtocheck[0]==pair[0]){
if (pairtocheck[1]==pair[1]){
return i;
}
}
}
return -1;
}
public void playerlocationchage(int xchange, int ychange){
playerx+=xchange;
playery+=ychange;
}

public int[] getplayerlocation(){
return new int[]{playerx, playery};
}
}
FILE6

package Fallin.engine;

import javafx.scene.layout.StackPane;

public class Cell extends StackPane {

}

DOWNLOAD LINK

https://www.mediafire.com/file/e54tpjddpbob912/ict221-fallin-2024-usc-LBB011.zip/file

1 Comment
2024/05/03
03:37 UTC

3

Can TestFX Robot browse for files or look through the File Explorer (Windows) for my JavaFX app?

Hi all,

For context, I'm new to JavaFX and TestFX. For anyone that has experience working with TestFX though, I want the robot to simulate some scenarios.

There is a button in the JavaFX application I'm adding tests to, which opens up the File Explorer and allows a user to browse for a file to import. Can I get the robot to simulate that same behavior via TestFX?

0 Comments
2024/05/02
16:40 UTC

0

Entire school have same "this.label" is null problem, help please?

We have a school homework about JavaFX and entire school having same error while trying to change a fx element from a function. Here is the codes.

Controller Code Pastebin TR : https://www.paste.tc/uicontrollerFunction is on line 98

Controller Code FXML: https://www.paste.tc/fxmlui-566labelUserName is on line 137

Controller Output: https://www.paste.tc/javaerrorError is on line 62

The problems happens on the 98th line, which happens with being called by setUserNName() function. When I try to change labelUserName with setText, I get this error bellow

Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.control.Label.setText(String)" because "this.labelUserName" is null

You might think it's because of FXML id correction but as you can see on link I shared, it have not any problems. Plus of this, same label could be changed via signalled functions on line 76 and 90. Also isAdmin value gets true and false, I debugged it.

Can someone help us to solve it?

13 Comments
2024/05/02
09:30 UTC

0

Can i learn JavaFX in just 5 days??

So this semester I had javafx course and my professor wasn’t really that great so I was on my phone throughout all of the lectures and in the first midterm exam the questions got leaked so I didn’t study for it. I was supposed to study after the exam but I got busy with other courses and now the second midterm exam is in 5 days and the project is due in less than 2 weeks and I’m fucked!! Do u think I can learn everything in just 5 days?? pls don’t come it me I know it’s all my fault

13 Comments
2024/04/30
23:17 UTC

3

IntelliJ JavaFX Project Template, Why Maven or Gradle Build Systems?

There used to a simple project JavaFX project template from IntelliJ, but it is nowhere to be found. If anyone knows why this is or how I can get the original template, the help would be appreciated.

https://preview.redd.it/94td9h9rpgxc1.png?width=752&format=png&auto=webp&s=c9605504cc195b63e2f1d18e133fef3b38a7f23e

It looked like this

7 Comments
2024/04/29
18:35 UTC

1

How to only return a variable when a certain key has been pressed

I am trying to write some code that takes the input from a textArea once enter was pressed, then returns it My problem is, that when the getInput() method is called it only checks once if enter is pressed, then returns null if its not here is my code:

static String getInput() {
        UI.textArea.setOnKeyPressed(ke -> {
            switch (ke.getCode()) {
                case KeyCode.ENTER:
                    System.out.println("-UserInput: Pressed Enter");
                    UI.preInput = UI.textArea.getText();
                    UI.lines = UI.preInput.split("\n");
                    if (UI.lines.length >= 1) {
                        input = UI.lines[UI.lines.length - 1];
                        System.out.println("-UserInput: " + input);
                    }
                    break;
                case KeyCode.ALT_GRAPH:
                    System.out.println("-UserALTGR:\nInput: " + input + "\nPathUser: " + userPath + "\nsignedIn: " + signedIn + "\naccountNumber: " + accountNumber);
                    getInput();
                    break;
            }
        });
        return input;
    }

    public static void signUpOrLogin() {
        say("Choose an option:\n[1] Sign up\n[2] Log in");
        switch (getInput()) {
            case "1":
                signUpUs();
            case "2":
                logInUs();
            case null:
                System.out.println("null");
            default:
                say("Invalid choice");
        }
    }

4 Comments
2024/04/29
12:32 UTC

1

Does JFX21 support 32-bit machines?

I tried to build JFX21 for Linux 32 bits and got some errors. Does anyone knows if this is actually supported?

Thanks

3 Comments
2024/04/27
21:40 UTC

3

Error while making a background video!

Hey guys! I'm new to JavaFx and just tried to create a background video but each time I get this error

https://preview.redd.it/5c5e6neq13xc1.png?width=1767&format=png&auto=webp&s=403fdde392c9d45e6831f554f75f89281ea42e5d

I searched and done all the ideas that came to my mind but still can't get it!.. I made sure of my video path, and when I changed the video to a background image it worked normally!
This is the code and project hierarchy:

https://preview.redd.it/ddzidgjb23xc1.png?width=1823&format=png&auto=webp&s=1e888b65f4e6fbbb3ac6eb7627b522962e39d76a

Any ideas?

2 Comments
2024/04/27
20:38 UTC

2

Custom shapes

Is there in way I can just make custom shapes, like blobs?

3 Comments
2024/04/26
23:32 UTC

1

Javafx maven:jlink module not found

I am working on a javaFX project in intellij, I'm using third party libraries like: javax.mail, JDBC...etc, When I run the project in intellij it works fine. Now that I want to export executable jar (this the first time I do this) I looked up on the internet and I found that you use maven javafx:jlink. So it start building normally until an error occurre "module not found: java.mail" If someone could tell me how to add it step by step I would be so thankful

3 Comments
2024/04/26
20:16 UTC

4

JavaFX for iOS mobile app using GluonFX with library leverage

Hello, Using GluonFX, we can build mobile apps for android and iOS. GluonFX is using its “attach” service for implementing the interface between Java and the mobile device

In attach repo there are examples how to use a library for android platform ( like QR scanning , Firebase ,…) but there is no examples about how to use external 3rd party library for iOS platform

Is it even possible to do that !? Can anybody give a hint for helping here ?

0 Comments
2024/04/25
20:17 UTC

1

Using FXML or not ?

13 Comments
2024/04/24
15:57 UTC

2

Any modern guides for generating platform-specific installers?

I’m interested in creating a cross-platform desktop application. I’ve been working with a mostly blank project all day, trying to figure out how generating an installer for a specific platform works.

I use Maven as my build tool, and run ‘mvn javafx:jlink’ to get (what I think is) a JRE that contains my code and the JavaFX libraries I need(?)

I also run ‘mvn install’ to get a .jar file that I can also use to run the project.

But from here, how can I go about creating an installer? I’m sorta confused on several fronts:

  1. I don’t quite understand what exactly the jlink command does for me, and what parts of that massive output I will actually need.

  2. How does that output from 1. different from the .jar file?

  3. How would a tool like JPackage know to use different JavaFX libraries if I were to target another platform?

Any advice, articles, or examples would be greatly appreciated.

11 Comments
2024/04/24
02:24 UTC

1

JavaFX runtime components are missing.

i keep getting the error Error: JavaFX runtime components are missing, and are required to run this application

However the only fix i have found was to separate the main out, so I had the App file (which originally had the psvm), and created a new class called Main, and put psvm there, which only did App.launch(). Edited the pom file to change the mainClass. Then the error I got there when I try to run the jar file is

Exception in thread "main" java.lang.RuntimeException: Error: class com.ritogames.Main is not a subclass of javafx.application.Application

at javafx.application.Application.launch(Application.java:298)

at com.ritogames.Main.main(Main.java:5)

Not sure why this is causing an issue, as everywhere specifically says it should be outside of javafx anyways.

I'll include my pom file below, it's probably very bloated after spending hours trying many many different solutions.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ritogames</groupId>
    <artifactId>fierydragons</artifactId>
    <version>1.0</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>12</version>
            <classifier>win</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>12</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>12</version>
        </dependency>

         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>12</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.ritogames.Main</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>com.ritogames.Main</mainClass>
                </manifest>
                </archive>
            </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.2</version>
                <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                    <goal>shade</goal>
                    </goals>
                    <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.ritogames.Main</mainClass>
                        </transformer>
                    </transformers>
                    </configuration>
                </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <!-- Configure it to "package" everything into a "single" jar -->
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- Extra options, like specifying the main class (containing main(string[] args)) -->
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.ritogames.Main</mainClass>
                        </manifest>
                    </archive>
                    <!-- Type of jar to create -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
4 Comments
2024/04/22
13:32 UTC

1

How to intersect with multiple nodes?

Hello guys, I need some help with this thing.

Basically, I have an array of nodes whereby i want to perform a check that, if a node of that array is intersecting with another node of that array - then do x, y, z etc.

How would I go about writing this code?

This will go into the loop body of a while loop, so it will continuously keep checking.

if (node1.getBoundsInParent().intersects(node2.getBoundsInParent())) {
                    System.out.println("node is intersecting");
}

So far I have written the above, which is 100% working, but I need it to check intersection between one node from an array with another node from the array, and it needs to include all the possible combinations e.g. node 1 with node 2, node 1 with node 4, node 4 with node 2.

The array sizes are dynamic, so it is possible that the array of nodes could be more or less.

I don't know how to "make" it do that, I can only think of a for loop which goes up to the size of the Array of Nodes, and get node at index 0, get node at index 1, then do the intersection check, but i don't think it will include cases where if i want to check node at index 0, with node at index 4...

Thanks, really appreciate the help

4 Comments
2024/04/21
17:27 UTC

8

JavaFX vs Kotlin Multiplatform

As Kotlin becomes more popular, will Kotlin Multiplatform have a good chance of overthrowing JavaFX? I tested it out, and it seems promising. Any opinions?

29 Comments
2024/04/20
22:32 UTC

1

Help with a problem in java fx

I'm currently trying to make a java fx program in netbeans that displays checkboxes for different pizza toppings, that when checked add 50 cents to the price of a 10 dollar pizza. I'm sure im doing something obviously wrong, but the program displays no errors besides warnings and tries to build and just can't . please help me im not sure what i'm doing wrong at all, here's the code below:

https://preview.redd.it/8krv774l2pvc1.png?width=763&format=png&auto=webp&s=21e363619a760dada025ab7cc8e60d334ef664c2

https://preview.redd.it/z3y4tq0o2pvc1.png?width=809&format=png&auto=webp&s=b3c6cb3bd282d6fb5c4d38f1b9753900557c6952

https://preview.redd.it/ko573ieq2pvc1.png?width=603&format=png&auto=webp&s=10b37756db6596bd9981998ec861720bff0b4ada

5 Comments
2024/04/20
20:31 UTC

7

Detecting the Biden Robocall Deep Fake using JavaFX

https://youtu.be/jI5r-flszzU?feature=shared

Demonstration of using javafx based XAI tool Trinity to detect the Biden robocall deepfake on aconsumer grade laptop. Presented last week at the 2024 DevNexus conference in Atlanta. 2024.

4 Comments
2024/04/20
00:35 UTC

4

Stackpane automatically resizing

public class CircleWithTextDynamicallySized extends Application {

    private double mouseX, mouseY;
    @Override
    public void start(Stage primaryStage) {
        // Create a stack pane to hold the circle and text
        StackPane root = new StackPane();
        root.setStyle("-fx-background-color: black");

        root.setOnMousePressed(event -> {
            // Store the initial mouse position
            mouseX = event.getSceneX();
            mouseY = event.getSceneY();
        });

        root.setOnMouseDragged(event -> {
            // Calculate the delta movement of the mouse
            double deltaX = event.getSceneX() - mouseX;
            double deltaY = event.getSceneY() - mouseY;

            // Move the StackPane by the delta values
            root.setTranslateX(root.getTranslateX() + deltaX);
            root.setTranslateY(root.getTranslateY() + deltaY);

            // Update the stored mouse position
            mouseX = event.getSceneX();
            mouseY = event.getSceneY();
        });

        // Create text
        String message = "Hello";
        Text text = new Text(message);
        text.setFont(Font.font(14)); // Set font size
        text.setFill(Color.WHITE); // Set text color
        text.setWrappingWidth(100); // Set the maximum width before wrapping. Wrap after a certain amount of pixels so we dont create massive nodes 
        text.setTextAlignment(TextAlignment.CENTER); // Center-align the text

        // Create a circle
        Circle circle = new Circle();
        double textWidth = text.getLayoutBounds().getWidth(); // get layout bounds returns the dimensions of the object
        double textHeight = text.getLayoutBounds().getHeight();
        double radius = Math.max(textWidth, textHeight) / 2; // Adjusted radius based on text size
        circle.setRadius(radius + 10); // add 5 so the text is not right on the edge of the circle
        circle.setFill(Color.RED); // Set fill color
        circle.setStroke(Color.BLACK); // Set stroke color

        // Add the circle and text to the stack pane
        root.getChildren().addAll(circle, text);

        root.setMaxSize(circle.getRadius(), circle.getRadius()); // set size of stackpane to rectangle surronding circle


        // Create the scene and set it on the stage
        Scene scene = new Scene(root); // Set scene size based on circle diameter
        scene.setFill(Color.LIGHTBLUE);


        primaryStage.setScene(scene);
        primaryStage.setFullScreen(true);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Hey, so I am a complete newbie to JavaFX. I am creating a circle with text to represent a node in a graph. I want to be able to drag the nodes around and place them wherever. To do this I need to be able to drag the circle around however the stackpane keeps resizing to the scene size which is resized to the size of the primaryStage's size. This means that I can essentially click anywhere to move the stack pane which is not what I want, instead, I want to click in the proximity of the circle and text so I want the stackpane to be a rectangle around the circle and text which is what I was hoping the

root.setMaxSize(circle.getRadius(), circle.getRadius());

line would achieve, but it still gets resized. The docs say

"

StackPane provides properties for setting the size range directly. These properties default to the sentinel value USE_COMPUTED_SIZE, however the application may set them to other values as needed:

// ensure stackpane is never resized beyond it's preferred size stackpane.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);

"

But it does not seem to be working for me, any help would be appreciated.

4 Comments
2024/04/18
10:43 UTC

1

javafx.media not working

I am making a small application in JavaFX and I want it to play sounds, but I cannot for the life of me get the media module to work. Cannot import it, cannot add it to module-info, nor can I add the maven dependency to pom.xml, anywhere I try it says it cannot be found.

How can I solve this?

4 Comments
2024/04/17
15:18 UTC

Back To Top