SlideShare a Scribd company logo
Introduction to
JavaFX Dialogs
HASUNUMA Kenji

k.hasunuma@coppermine.jp
@khasunuma
Overview
JavaFX Dialogs (8u40)
• Alert - returns any ButtonType

• TextInputDialog - returns input text

• ChoiceDialog - returns choosen item

• Dialog - superclass of all dialogs
Alert - INFORMATION
Alert - WARNING
Alert - ERROR
Alert - CONFIRMATION
Alert - NONE
TextInputDialog
ChoiceDialog
Usage
Dialog on code
• Works instead of Stage.

• Often, exists into a controller as a part of
event procedures.

• showAndWait() - show and wait, then
returns a value as Optional<R>.
• show() - show and wait, then returns no
value.
Layout
DialogPane
ButtonTypes
Graphic
HeaderText
ContentText
Dialog
// Create a dialog

Alert alert = new Alert(INFORMATION);

!
// Setting properties

alert.setTitle("Title (INFORMATION)");

alert.setHeaderText("Header Text");

alert.setContentText("Content Text");

!
// Show and obtain the result

Optional<ButtonType> result 

= alert.showAndWait();

!
// Another way if the result is needless

// alert.show();
Result types
Dialog Result type
Alert
ButtonType

!
OK, CANCEL, CLOSE, APPLY,
FINISH, YES, NO, NEXT, PREVIOUS
TextInputDialog String
ChoiceDialog Type of choosen item
Tips
I want such a dialog...
How?
I want such a dialog...
How?
// Add following code

alert.setHeaderText(null);
/**

* Tips #2: the way to resize a dialog.

*/

public class SomeController {

@FXML

public void onClick(ActionEvent event) {

. . .

Alert alert = new Alert(INFORMATION);
// Using following methods to resize;
// setPrefWidth, setPrefHeight and setPrefSize
alert.getDialogPane().setPrefSize(400.0, 300.0);
Optional<String> result = dialog.showAndWait();
/* Handle the result */
}

}
/**

* Tips #3: Simple dialog-based application.

*/

public class DialogApp extends Application {

@Overrides

public void start(Stage stage) throws Exception {

TextInputDialog dialog = new TextInputDialog();
/* setting the dialog */
Optional<String> result = dialog.showAndWait();
/* handle the result */
}



public static void main(String...args) {

launch(args);

}

}
Conclusion
• The representation of JavaFX dialogs
are Dialog and their subclasses.

• JavaFX Dialog looks like Stage, but is
not Stage.

• At first create and configure a dialog,
and call showAndWait method.
Introduction to
JavaFX Dialogs
HASUNUMA Kenji

k.hasunuma@coppermine.jp

@khasunuma

More Related Content

What's hot

Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
rit2010
 

What's hot (20)

AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and Components
 
AWT
AWT AWT
AWT
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
 
Alexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java FxuiAlexandre Iline Rit 2010 Java Fxui
Alexandre Iline Rit 2010 Java Fxui
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
25 awt
25 awt25 awt
25 awt
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
Mastering your Eclipse IDE - Tips, Tricks, Java 8 tooling & More!
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
What's cool in Eclipse goody bag!
What's cool in Eclipse goody bag!What's cool in Eclipse goody bag!
What's cool in Eclipse goody bag!
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Eclipse Tips & Tricks
Eclipse Tips & TricksEclipse Tips & Tricks
Eclipse Tips & Tricks
 
Event handling
Event handlingEvent handling
Event handling
 
Swing
SwingSwing
Swing
 
High productivity development with Eclipse and Java 8
High productivity development with Eclipse and Java 8High productivity development with Eclipse and Java 8
High productivity development with Eclipse and Java 8
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Chapter 1 swings
Chapter 1 swingsChapter 1 swings
Chapter 1 swings
 

Similar to Introduction to JavaFX Dialogs

Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extra
rit2010
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
daotuan85
 

Similar to Introduction to JavaFX Dialogs (20)

Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed content
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
GUI programming
GUI programmingGUI programming
GUI programming
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
 
Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extra
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Python basics
Python basicsPython basics
Python basics
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Gui
GuiGui
Gui
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Eclipse Summit Europe '10 - Test UI Aspects of Plug-insEclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
 
Modernize Your Real-World Application with Eclipse 4 and JavaFX
Modernize Your Real-World Application with Eclipse 4 and JavaFXModernize Your Real-World Application with Eclipse 4 and JavaFX
Modernize Your Real-World Application with Eclipse 4 and JavaFX
 
Db Triggers05ch
Db Triggers05chDb Triggers05ch
Db Triggers05ch
 
TDD by Controlling Dependencies
TDD by Controlling DependenciesTDD by Controlling Dependencies
TDD by Controlling Dependencies
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
 
Enterprising JavaFX
Enterprising JavaFXEnterprising JavaFX
Enterprising JavaFX
 

More from Kenji HASUNUMA

More from Kenji HASUNUMA (15)

How to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applicationsHow to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applications
 
Life of our small product
Life of our small productLife of our small product
Life of our small product
 
Jakarta EE: The First Parts
Jakarta EE: The First PartsJakarta EE: The First Parts
Jakarta EE: The First Parts
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile MetricsIntroduction to MicroProfile Metrics
Introduction to MicroProfile Metrics
 
Introduction to JCA and MDB
Introduction to JCA and MDBIntroduction to JCA and MDB
Introduction to JCA and MDB
 
Basic method for Java EE Web Profile
Basic method for Java EE Web ProfileBasic method for Java EE Web Profile
Basic method for Java EE Web Profile
 
Brand New Date and Time API
Brand New Date and Time APIBrand New Date and Time API
Brand New Date and Time API
 
Virtualization Fundamental
Virtualization FundamentalVirtualization Fundamental
Virtualization Fundamental
 
JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
 
Fundamental Java
Fundamental JavaFundamental Java
Fundamental Java
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2Introduction to Date and Time API 2
Introduction to Date and Time API 2
 
Introduction to Date and Time API
Introduction to Date and Time APIIntroduction to Date and Time API
Introduction to Date and Time API
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 

Introduction to JavaFX Dialogs

  • 1. Introduction to JavaFX Dialogs HASUNUMA Kenji k.hasunuma@coppermine.jp @khasunuma
  • 3. JavaFX Dialogs (8u40) • Alert - returns any ButtonType • TextInputDialog - returns input text • ChoiceDialog - returns choosen item • Dialog - superclass of all dialogs
  • 11. Usage
  • 12. Dialog on code • Works instead of Stage. • Often, exists into a controller as a part of event procedures. • showAndWait() - show and wait, then returns a value as Optional<R>. • show() - show and wait, then returns no value.
  • 14. // Create a dialog Alert alert = new Alert(INFORMATION); ! // Setting properties alert.setTitle("Title (INFORMATION)"); alert.setHeaderText("Header Text"); alert.setContentText("Content Text"); ! // Show and obtain the result Optional<ButtonType> result = alert.showAndWait(); ! // Another way if the result is needless // alert.show();
  • 15. Result types Dialog Result type Alert ButtonType ! OK, CANCEL, CLOSE, APPLY, FINISH, YES, NO, NEXT, PREVIOUS TextInputDialog String ChoiceDialog Type of choosen item
  • 16. Tips
  • 17. I want such a dialog... How?
  • 18. I want such a dialog... How? // Add following code alert.setHeaderText(null);
  • 19. /** * Tips #2: the way to resize a dialog. */ public class SomeController { @FXML public void onClick(ActionEvent event) { . . . Alert alert = new Alert(INFORMATION); // Using following methods to resize; // setPrefWidth, setPrefHeight and setPrefSize alert.getDialogPane().setPrefSize(400.0, 300.0); Optional<String> result = dialog.showAndWait(); /* Handle the result */ } }
  • 20. /** * Tips #3: Simple dialog-based application. */ public class DialogApp extends Application { @Overrides public void start(Stage stage) throws Exception { TextInputDialog dialog = new TextInputDialog(); /* setting the dialog */ Optional<String> result = dialog.showAndWait(); /* handle the result */ } public static void main(String...args) { launch(args); } }
  • 22. • The representation of JavaFX dialogs are Dialog and their subclasses. • JavaFX Dialog looks like Stage, but is not Stage. • At first create and configure a dialog, and call showAndWait method.
  • 23. Introduction to JavaFX Dialogs HASUNUMA Kenji k.hasunuma@coppermine.jp @khasunuma