JavaFX rendering issue on OSX after java upgrade - java

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.

Related

JavaFX 18.0.1 + Windows 11 + JDK 18.0.1.1: Canvas - cannot trigger the touch screen events

My setup:
JavaFX SDK 18.0.1
Windows 11
JDK 18.0.1.1
A screen with the touch support
When I try a simple program, none of the touch events are triggered upon touch gestures. My test app follows.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.input.TouchEvent;
import javafx.stage.Stage;
public class JavaFXSandbox extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Scene scene = new Scene(root, 600, 600);
Canvas canvas = new Canvas(600, 600);
root.getChildren().add(canvas);
stage.addEventFilter(TouchEvent.ANY, e -> System.out.println("touch event: " + e));
stage.setScene(scene);
stage.show();
}
}
Is there any way of circumventing the issue, or am I misusing the JavaFX API?
After playing a bit with JavaFX, I found out that touch events are converted to mouse events such, that it's possible to simulate touch events in mouse listeners.

JavaFX - Resizable with Java 10

I'm new in Java 10, I think I caught a bug.
Snippet:
stage.setResizable(false);
stage.setScene(new Scene(new Group()));
stage.show();
At Java 8: Give us a window with dimensions 200x100.
At Java 10: Give us a window with dimensions 1x20.
Use FXML with BorderPane and prefWidth / prefHeight - did not fix problem.
Workaround: do not use setResizable. Instead, use setMinWidth&setMaxWidth / setMinHeight&setMaxHeight.
Tested on Linux with Java 10.0.2.
Sorry if dublicate or existing bug, I just wanted to share a discovery.
Full code:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage stage) {
stage.setResizable(false);
stage.setScene(new Scene(new Group()));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}

modal JavaFX stage initOwner prevents owner from resizing, bug?

If I open another JavaFX (modal) Stage, and set its owner as the original Stage, then the original Stage can't be resized, using the windows drag widget on the bottom right hand corner of the window
I see this in Linux but don't own windows or MacOS so can't test it elsewhere...
here is a minimal example
import javafx.stage.*;
import javafx.scene.*;
import javafx.event.*;
import javafx.application.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
public class HelloWorld extends Application
{
static Stage newStage;
#Override
public void start(Stage primaryStage)
{
Button btn = new Button();
btn.setText("open window");
btn.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent event)
{
if (newStage==null)
{
Button newBtn = new Button("Close window");
newBtn.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent event)
{
//newStage.hide(); // either or
newStage.close();
}
});
newStage = new Stage();
newStage.initModality(Modality.WINDOW_MODAL);
newStage.initOwner(primaryStage); // BUG doing this, makes main window fixed size
newStage.initStyle(StageStyle.DECORATED);
StackPane newRoot = new StackPane();
newRoot.getChildren().add(newBtn);
Scene newScene = new Scene(newRoot,200,160);
newStage.setScene(newScene);
}
newStage.show();
}
});
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);
}
}
This is a confirmed Java bug. Looks like it's targeted for fixing in Java 10 sometime.
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8140491
That said, I'd love a workaround if someone has one.
Edit: one workaround I've found, ugly as it is, is that you can hide and show the owner stage after hiding the modal child stage. That re-enables resizing. You see the stage disappear and reappear, though, which is messy.

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

JavaFX: Undecorated Window

I am attempting to make a Windows PC Toast notification. Right now I am using a mixture of Swing and JavaFX because I did not find a way to make an undecorated window with FX. I would much prefer to only use JavaFX.
So, how can I make an undecorated window?
Edit: I have discovered that you can create a stage directly with new Stage(StageStyle.UNDECORATED).
Now all I need to know is how to initialize the toolkit so I can call my start(Stage stage) method in MyApplication. (which extends Application)
I usually call Application.launch(MyApplication.class, null), however that shields me from the creation of the Stage and initialization of the Toolkit.
So how can I do these things to allow me to use start(new Stage(StageStyle.UNDECORATED)) directly?
I don't get your motivation for preliminary calling the start()-method setting a stage as undecorated, but the following piece of code should do what you want to achieve.
package decorationtest;
import javafx.application.Application;
import javafx.stage.StageStyle;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class DecorationTest extends Application {
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.initStyle(StageStyle.UNDECORATED);
Group root = new Group();
Scene scene = new Scene(root, 100, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
}

Categories

Resources