Cannot resolve symbol 'StackPane' Intelij IDEA - java

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.

Related

How to achive the effect of UNDECORATED + UTILITY in javafx? [duplicate]

I need remove my javafx app from the taskbar. I tried StageStyle.UTILITY. This is works but I need both UNDECORATED and UTILITY stage styles or another solvings.
Thank you for your replies.
Sorry you've been waiting so long for some sort of an answer on this, the following is mainly for people who come to this in the future hoping to discover a way of achieving this.
Let me start of by saying I wouldn't consider the following a solution but more of a workaround.
Assigning more than one initStyle to a stage is not possible however hiding the application from the task-bar and assigning an initStyle other than utility to the stage that is shown is.
To achieve this one must create two stages, the stage they want the user to see, and an another stage that will be considered the parent of the main stage and will be of initStyle.UTILITY this will prevent the icon from showing in the task-bar.
Below you can see the hello world example from oracles documentation modified to allow for an undecorated window with no icon (Note if one wanted to achieve a transparent/decorated window they could do so by changing the style of mainStage).
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;
import javafx.stage.StageStyle;
public class MultipleStageStyles extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setOpacity(0);
primaryStage.setHeight(0);
primaryStage.setWidth(0);
primaryStage.show();
Stage mainStage = new Stage();
mainStage.initOwner(primaryStage);
mainStage.initStyle(StageStyle.UNDECORATED);
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);
mainStage.setScene(new Scene(root, 300, 250));
mainStage.show();
}
}

Window not showing up on Mac 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

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

JavaFX 8: Blank scene after monitor out of standby

I'm having a weird issue with JavaFX (jdk8, build 117): once the monitor resumes from standby the JavaFX stage/scene is blank.
I've tried minimizing/resizing the window but the contents are no longer displayed. I'm using a simple scene with a StackPane.
root = new StackPane();
root.setBackground(null);
scene = new Scene(root, Color.BLACK);
stage.setScene(scene);
ProgressIndicator piLoader = new ProgressIndicator();
piLoader.setMaxSize(32d, 32d);
root.getChildren().add(piLoader);
stage.show();
I've tried searching for a known bug or a previous report but could not find any.
JDK8 is still very much in flux & marked as an early access release, so issues like this should be expected. I've just tested it on JDK8 built b121 (Win8 64bit & Ubuntu 13.10 64bit) and it appears to be fine.
Update your JDK version to the latest & see if that resolves the issue for you.
UPDATE: Here's a full stock-standard example that works without problem for me, monitor goes into sleep mode & comes back without any display issues. 'Sleep mode' is the only option Windows 8 is giving me, so not 'Standby' as you're referring to. Which OS are you using?
package helloworld;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class HelloWorld 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.setBackground(null);
root.getChildren().add(btn);
ProgressIndicator piLoader = new ProgressIndicator();
piLoader.setMaxSize(32d, 32d);
root.getChildren().add(piLoader);
Scene scene = new Scene(root, 300, 250, Color.BLACK);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

Categories

Resources