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);
}
}
Related
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();
}
}
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.
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
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();
}
}
My app with javafx 3D objects was working fine until I upgraded java from 8u51 to 8u60.
After the upgrade, the UI is displayed upside down.
Here is what I get with the following test code. It seems the y axis is reversed in rendering but not in functionality.
I have tried to put -Dprism.order=sw as a VM option. This fixes the test problem,
but then does not allow javafx 3D objects to be rendered.
Does anyone knows how to fix this java/javafx issue. I will try to download and install Java 8u51.
Note, I have read JavaFX Mac OS strange rendering .
import javafx.application.Application;
import javafx.scene.PerspectiveCamera;
import javafx.scene.SceneAntialiasing;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.scene.Scene;
public class TestAppj extends Application {
public static void main(String[] args) { Application.launch(args); }
public void start(Stage primaryStage) {
primaryStage.setTitle("Test Stage");
TabPane tabbedPane = new TabPane(new Tab("Tools", new BorderPane()), new Tab("Things", new BorderPane()));
MenuBar menuBar = new MenuBar(
new Menu("File", null, new MenuItem("Open"), new MenuItem("New"), new MenuItem("Save")),
new Menu("Edit", null, new MenuItem("Cut"), new MenuItem("Copy"), new MenuItem("Paste")));
BorderPane root = new BorderPane();
root.setTop(new VBox(menuBar, new ToolBar()));
root.setCenter(tabbedPane);
Scene theScene = new Scene(root, 500, 500, true, SceneAntialiasing.BALANCED);
theScene.setCamera(new PerspectiveCamera());
primaryStage.setScene(theScene);
primaryStage.show();
}
}
This is a shorter way to reproduce the bug you have found with 8u60 on Mac:
#Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new StackPane(new Label("Antialising\nBalanced")),
300, 300, true, SceneAntialiasing.BALANCED);
primaryStage.setScene(scene);
primaryStage.show();
}
The problem is not in the camera, but just in the antialiasing.
Workaround for now on Mac: use SceneAntialiasing.DISABLED. That will work as usual and you will be able to add 3D objects.