fontchooser-example.2.4.source-code.DialogExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fontchooser-example Show documentation
Show all versions of fontchooser-example Show documentation
Example on how to use the Java Swing Font Chooser component
The newest version!
import org.drjekyll.fontchooser.FontDialog;
import javax.swing.*;
import java.awt.Frame;
import java.lang.reflect.InvocationTargetException;
public class DialogExample implements Runnable {
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
ExampleRunner.useLookAndFeel(UIManager.getSystemLookAndFeelClassName());
ExampleRunner.invoke(new DialogExample());
}
@Override
public void run() {
FontDialog dialog = new FontDialog((Frame) null, "Select Font", true);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (!dialog.isCancelSelected()) {
System.out.printf("Selected font is: %s%n", dialog.getSelectedFont());
}
}
}