0% found this document useful (0 votes)
2 views12 pages

Topic 15 Swing Vs JavaFX

The document outlines the evolution of Java GUI frameworks from AWT, introduced in 1995, to Swing in 1998, and finally to JavaFX in 2008. AWT was the first toolkit but had limitations such as platform dependency and poor performance, while Swing improved upon it with lightweight components and a pluggable look and feel, though it lacked modern features. JavaFX is presented as the modern solution for rich internet and desktop applications, offering advanced features like CSS styling, multimedia support, and a clear separation of UI and logic.

Uploaded by

sworupraj56
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Topic 15 Swing Vs JavaFX

The document outlines the evolution of Java GUI frameworks from AWT, introduced in 1995, to Swing in 1998, and finally to JavaFX in 2008. AWT was the first toolkit but had limitations such as platform dependency and poor performance, while Swing improved upon it with lightweight components and a pluggable look and feel, though it lacked modern features. JavaFX is presented as the modern solution for rich internet and desktop applications, offering advanced features like CSS styling, multimedia support, and a clear separation of UI and logic.

Uploaded by

sworupraj56
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

History of Java GUI: AWT → Swing → JavaFX

AWT (Abstract Window Toolkit) – First Generation


Introduced
 1995 (Java 1.0)
Package
 [Link]

What is AWT?
AWT was Java’s first GUI toolkit, used to build basic
graphical user interfaces.
Key Features
 Uses native OS components (Heavyweight)
 Platform dependent look
 Limited set of components

Example Components
 Button
 Label
 TextField
 Checkbox
 Frame
Limitations of AWT
Platform dependent
Inconsistent look & feel
Limited UI components
Poor performance
No advanced controls

Conclusion: AWT was simple but insufficient for complex


applications.

Swing – Second Generation


Introduced
 1998 (Java 1.2)
Package
 [Link]

Why Swing Was Introduced?


Swing was introduced to overcome AWT limitations.

Key Features
 Lightweight components
 Platform independent
 Pluggable Look & Feel
 Rich set of components
 MVC architecture

Example Components
 JButton
 JLabel
 JTextField
 JTable
 JTree
 JMenu

Limitations of Swing
Old-fashioned UI
No CSS styling
No built-in animation
No multimedia support
Complex layout management

Conclusion: Swing improved AWT greatly but lacked modern


UI features.
JavaFX – Third Generation
Introduced
 2008 (Officially included in Java 8)
Package
 javafx.*

Why JavaFX Was Introduced?


JavaFX was developed to create modern, rich internet and
desktop applications.
Key Features
 Scene Graph architecture
 CSS styling
 FXML (UI design separate from logic)
 Animation & Effects
 Multimedia support
 Hardware acceleration
Example Components
 Button
 Label
 TextField
 TableView
 MediaPlayer
Conclusion: JavaFX is modern, flexible, and future-ready.

Timeline Summary (VERY IMPORTANT)

Year Technology Description

1995 AWT Basic GUI toolkit

1998 Swing Rich & portable GUI

2008 JavaFX Modern UI framework

Evolution Comparison Table (Exam Focus)

Feature AWT Swing JavaFX

Component Type Heavyweight Lightweight Lightweight

Look & Feel OS dependent Pluggable CSS based

Performance Slow Moderate Fast

Components Limited Rich Very rich


Feature AWT Swing JavaFX

Animation ❌ ❌ ✔

Multimedia ❌ ❌ ✔

Styling ❌ ❌ ✔

Current Status Obsolete Legacy Recommended

Simple Evolution Diagram (Write in Exam)


AWT (1995)

Swing (1998)

JavaFX (2008)

 AWT: Java’s first GUI toolkit, platform dependent.


 Swing: Improved AWT with lightweight, portable
components.
 JavaFX: Modern GUI framework with CSS, FXML, and
multimedia support.
Tips
AWT uses native components
Swing uses JComponents
JavaFX uses Scene & Stage
JavaFX is the future of Java GUI
Java Swing vs JavaFX
Basic Introduction

Swing

 Older Java GUI framework


 Part of Java SE

 Built on top of AWT

 Uses imperative programming style

JavaFX

 Modern Java GUI framework

 Introduced to replace Swing


 Supports declarative UI (FXML)
 Designed for rich, modern interfaces

Difference Table

Feature Swing JavaFX

Package [Link] javafx.*

Year 1998 2008

UI Style Traditional Modern, Rich UI

Look & Feel Platform dependent CSS-based

Layout Layout Managers Layout Panes

UI Design Code only Code + FXML

Graphics Limited Advanced (2D/3D)

Multimedia Not supported Audio & Video

Threading EDT (Event Dispatch Thread) JavaFX Application Thread


Feature Swing JavaFX

Styling Not supported CSS

Animation Not supported Built-in

Performance Moderate Better & smoother

Future Support Maintenance mode Actively developed

Architecture Difference

Swing Architecture

 MVC (Model-View-Controller)

 Heavy reliance on event handling

 UI tightly coupled with logic


JavaFX Architecture

 Scene Graph based

 Clear separation of UI and logic

 Better maintainability

Simple Program Example (Swing)

Swing: Hello World GUI

import [Link].*;

public class SwingExample {

public static void main(String[] args) {

JFrame frame = new JFrame("Swing Example");

JButton btn = new JButton("Click Me");

[Link](100, 50, 120, 30);


[Link](btn);

[Link](null);

[Link](300, 200);

[Link](JFrame.EXIT_ON_CLOSE);

[Link](true);

Simple Program Example (JavaFX)

JavaFX: Hello World GUI

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class JavaFXExample extends Application {

@Override

public void start(Stage stage) {

Button btn = new Button("Click Me");

StackPane root = new StackPane(btn);

Scene scene = new Scene(root, 300, 200);

[Link]("JavaFX Example");
[Link](scene);

[Link]();

public static void main(String[] args) {

launch(args);

Layout Handling Difference

Swing

[Link](new BorderLayout());
JavaFX

BorderPane root = new BorderPane();

Event Handling Difference

Swing

[Link](e ->

[Link](null, "Clicked"));
JavaFX

[Link](e ->

[Link]("Clicked"));

Styling Difference

Swing

 Uses Look & Feel

[Link](
[Link]());
JavaFX

 Uses CSS

.button {

-fx-background-color: blue;

-fx-text-fill: white;

When to Use What?

Use Swing When:

Working on legacy systems


Simple desktop applications
Exam-level programs
Use JavaFX When:

Modern UI required
Animations & media needed
Future-proof applications

Swing is an older Java GUI framework with traditional UI, whereas JavaFX is a
modern, feature-rich GUI framework supporting CSS, multimedia, and FXML.

Tips

 Swing uses JFrame, JavaFX uses Stage

 Swing uses Layout Manager, JavaFX uses Layout Pane


 JavaFX supports FXML & CSS

You might also like