Skip to content

A Java Swing Component to choose a font according to the list of available font families, styles and sizes.

License

Notifications You must be signed in to change notification settings

Magillem/fontchooser

 
 

Repository files navigation

Java Swing Font Chooser Dialog and Panel

Java does not provide a lightweight font chooser out of the box. This easy to use Java Swing font chooser component allows users to select a font by selecting a font family name and the installed font variants. Users are able to search for a font and insert their own preview text.

This font chooser is fully Java 9 compatible.

Cross Platform

Font Chooser (Cross Platform)

GTK / Linux

Font Chooser (GTK)

Aqua / Mac

Font Chooser (Aqua)

Windows

Font Chooser (Windows)

Motif / Common Desktop Environment

Font Chooser (Motif)

There are translations for the following languages:

  • English
  • German
  • Greek
  • Spanish
  • Finnish
  • French
  • Brazilian Portuguese
  • Russian

Font Chooser is an open source project and completely free. I appreciate improvements or extensions. Please contact me if you have questions.

Continuous Integration

Build Status Windows Build Status Coverage Status Maven Central

Building

mvn install

Usage

Include the following dependency to your project:

<dependency>
    <groupId>io.github.dheid</groupId>
    <artifactId>fontchooser</artifactId>
    <version>2.0</version>
 </dependency>

If you want to apply a font to a specific component, e.g. a text area, simply use

JTextArea textArea = new JTextArea();
FontDialog.showDialog(textArea);

This will display the modal font dialog and apply the font to the component, if the user clicked OK.

Here is another simple example on how to use the font chooser dialog in your application:

FontDialog dialog = new FontDialog((Frame) null, "Font Dialog Example", true);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (!dialog.isCancelSelected()) {
  System.out.printf("Selected font is: %s%n", dialog.getSelectedFont());
}                                                               

You'll find more examples in the module fontchooser-example:

Contributing

Any help is welcome. Especially translations are very useful. You can open bug reports or feature requests or implement new features.

  1. Fork it!
  2. Apply your changes and don't forget to add unit tests.
  3. Build using Maven and ensure, that the build was successful.
  4. Commit and push your changes.
  5. Submit a pull request

Credits

This is a major rewrite of the JFontChooser component, originally written by Dr Christos Bohoris (Copyright 2009).

License

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 https://www.gnu.org/licenses/lgpl-3.0.en.html

About

A Java Swing Component to choose a font according to the list of available font families, styles and sizes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%