Window not showing up on Mac JAVA - java

package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
public class Main extends Application {
Button button;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
stage.setTitle("GAME");
button = new Button();
button.setText("CLICK HERE");
StackPane layout = new StackPane();
layout.getChildren().add(button);
Scene scene = new Scene(layout, 300, 250);
stage.setScene(scene);
stage.show();
}
}
Trying to run but the window won't show up, any thoughts on how to fix. I've gone through other posts but no luck. By the way, I'm using IntelliJ. Just started learning JavaFX.

This is in my .bash_profile:
export PATH_TO_FX=/usr/local/bin/javafx-sdk-14/lib
alias javafxc="javac --module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml,javafx.media,javafx.web,javafx.swing"
alias javafx="java --module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml,javafx.media,javafx.web,javafx.swing"
To compile:
javafxc Main.java
To run:
javafx Main

Related

Cannot resolve symbol 'StackPane' Intelij IDEA

I tried to run this code in intelij IDE, but it shows an error, java: cannot find symbol, symbol: class StackPane
But when I tried the same code on Netbeans IDE, it worked well. what could be the reason for that?
package javafxfirstproject;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class JavaFxFirstProject extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
You should follow Intellij IDEA JavaFX tutorial, especially Adding the JavaFX library and Add VM options.
Here is post with simillar issue.
Go through this YouTube tutorial, your code works on my computer after completing this tutorial.

JavaFX Stage not visible

I'm trying to write the simplest code to start learning how JavaFX works. Here is my code:
package app;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class mainClass extends Application{
Stage primaryStage;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
primaryStage = stage;
StackPane layout = new StackPane();
Scene scene = new Scene(layout, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
}
It should just show an empty window. My compilator gives no errors, but nothing shows up, even if I can see my program running in my dock. How is this possible? I'm sure I'm missing some stupid simple thing, but I cannot figure out what it is.

When I run JavaFx class on my Mac, no window appears but a java icon appears in my dock

Can someone help please, when I run a JavaFx class on my Mac, no window appears but a java icon appears in my dock. When I click to show this file in finder, I see a file called java- Unix executable. I have no idea what is wrong, I have tried so many tutorials.
I am running this program on eclipse with jdk 12 and JavaFx13.
This is my code:
package JavaFx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class JavaFx extends Application {
Button button;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage lol) throws Exception {
lol.setTitle("Title");
button = new Button();
button.setText("Click me");
StackPane layout = new StackPane();
layout.getChildren().add(button);
Scene scene = new Scene(layout, 300, 250);
lol.setScene(scene);
lol.show();
}
}

Label will not show on GUI

I have a GUI, however, when I try to add a Label the screen it does not seem to add correctly.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class GUI extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
Label labe = new Label("Test");
Button button = new Button("ASDf");
TilePane tilePane = new TilePane();
tilePane.getChildren().addAll(labe, button);
Scene scene = new Scene(tilePane, 100, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
}
I get the following result When I run the above code
I am running this in IntelliJ with java version 1.7
How do I get my label to show also?

Why doesn't button add to scene?

package application;
import java.awt.Button;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
public class Main extends Application {
Button button; //Declare Button
public static void main(String[] args) {
launch(args); //calls application
}
#Override
public void start(Stage primaryStage) throws Exception {
//comes from application pack
primaryStage.setTitle("Title Of Window"); //Main Stage
button = new Button (); //Creates Button
button.setLabel("Click Me");
StackPane layout = new StackPane();
layout.getChildren().add(button); //Button in Scene
Scene scene = new Scene (layout, 300, 250); //Sets Scene
primaryStage.setScene(scene); //Stage and Scene
primaryStage.show();
}
Hey guys, so this is first time I am creating something in JavaFX and I was wondering why doesn't my button in Scene add in Layout.GetChildren() line, it keeps on displaying red line underneath add. I am using Eclipse IDE.
you have imported import java.awt.Button, you must import Button class in the javafx package.

Categories

Resources