Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to use AWT with JavaFx?

Tags:

java

awt

javafx-2

I need some functionality that I cannot find currently in JavaFX. Like the Robot or the Tray Icon.

I know these tools do work with JavaFx applications. But is it ok to use them? Are there any considerations that I should care of?

like image 488
betaman Avatar asked Jun 20 '12 12:06

betaman


People also ask

Is JavaFX AWT Java?

Java awt is the first generation, Java Swing is the second generation and the JavaFx is the third generation UI-Toolkit for designing and implementing Graphical User Interfaces with Java.

Why is JavaFX preferred to AWT and Swing?

Swing is the standard toolkit for Java developer in creating GUI, whereas JavaFX provides platform support for creating desktop applications. Swing has a more sophisticated set of GUI components, whereas JavaFX has a decent number of UI components available but lesser than what Swing provides.

Is Java AWT still used?

JavaFX new fixes will continue to be supported on Java SE 8 through March 2022 and removed from Java SE 11. Swing and AWT will continue to be supported on Java SE 8 through at least March 2025, and on Java SE 11 (18.9 LTS) through at least September 2026.

Can you use Java Swing with JavaFX?

A JavaFX Scene can be integrated into Swing code via the JavaFX class JFXPanel and its setScene(Scene) method.


1 Answers

Generally it's not advised.

N.B.:

  • using any AWT from JavaFX will start whole AWT stack which can increase memory/proc consumption.
  • there could be threading conflicts between Glass (FX UI stack) and AWT, especially on Mac. So it maybe worth using Swing Interoperability approach for your app as JFXPanel is aware how to handle that conflicts.
  • you can use Glass robot instead of AWT one (although it's not public API and may be changed in future):

    Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
    robot.mouseMove(10, 30);
    robot.mousePress(1);
    
like image 146
Sergey Grinev Avatar answered Sep 28 '22 07:09

Sergey Grinev