Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

A javax.swing.JComboBox allows us to choose one out of five different dialogs.

After choosing 'File', a javax.swing.JFileChooser is created.

We then create an instance of our class OurFilter.

This extends javax.swing.filechooser.FileFilter...

and arranges, that only directories and txt files are shown.

We set the filter on the dialog and show it.

If the user has chosen a file and confirmed,...

a java.io.File reference can be retrieved by calling getSelectedFile.

=== 'Color' chosen from combo : ===

Calling JColorChooser's static method showDialog will result in a valid Color reference, after the user has confirmed the dialog.

Green is passed as initial color.

=== 'Message' chosen : ===

A simple message box is shown.

And one with a title and an icon.

=== 'Confirm' chosen : ===

A confirm dialog is shown

with Yes and No buttons.

If the user has confirmed by clicking Yes,

the label is set accordingly.

=== 'Input' chosen : ===

An input dialog is shown

that results in a reference to a String.

.