- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create modeless and model JDialog in Java?
MODELESS Type
The following is an example to set JDialog with Modality type MODELESS −
Example
import java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(new Dimension(600, 400)); JDialog dialog = new JDialog(frame, "New",ModalityType.MODELESS); dialog.setSize(300, 300); frame.add(new JButton(new AbstractAction("Click to generate") { @Override public void actionPerformed(ActionEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dialog.setVisible(true); } })); frame.setVisible(true); } }
Output
Now, click on it to generate a new Dailog. You can close both the dialog at any time since it is Modeless −
Model Dialog
The following is an example for model Dialog −
Example
import java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(new Dimension(600, 400)); JDialog dialog = new JDialog(frame, "New",ModalityType.APPLICATION_MODAL); dialog.setSize(300, 300); frame.add(new JButton(new AbstractAction("Click to generate") { @Override public void actionPerformed(ActionEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dialog.setVisible(true); } })); frame.setVisible(true); } }
Output
Now, click on it to generate a new Dailog. You cannot close both the dialog at any time since it isn’t Modeless. You have to first close the new Dialog, the you will be able to close the first −
- Related Articles
- What happens when JDialog is set with Modality type MODELESS in Java
- How can we implement transparent JDialog in Java?
- How to create a JSON Array using Object Model in Java?
- How to create a JSON Object using Object Model in Java?
- How to create a JSON using Jackson Tree Model in Java?
- How to Create a Model in Backbone.js?
- What are the differences between JFrame and JDialog in Java?\n
- How many types of JDialog boxes can be created in Java?
- How to create polynomial regression model in R?
- How to create a polynomial model in R?
- How can Tensorflow and pre-trained model be used to create base model from pre-trained convnets?
- How to create an only interaction regression model in R?
- How to create confusion matrix for a rpart model in R?
- How to create a linear model with interaction term only in R?
- How to parse a JSON to Gson Tree Model in Java?

Advertisements