Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4622604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:52:01+00:00 2026-05-22T02:52:01+00:00

I am creating a swing font chooser. (See also: How to prevent JComboBox from

  • 0

I am creating a swing font chooser. (See also: How to prevent JComboBox from becoming unresponsive when using a custom ListCellRenderer)

To get all available fonts, I do:

GraphicsEnvironment gE = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = gE.getAllFonts();

In my font chooser (a JComboBox), which contains all the available fonts, I want to initialize it showing the default system font as selected.

To do this, I use a static base font (which is gotten from a static base label (a JLabel)), from which I get the default font.
Then, during initialization of the JComboBox, I call

fontComboBox.setSelectedItem(new Font(baseFont.getName(),baseFont.getStyle(),1)); 
//The size is 1 in all fonts retrieved from GraphicsEnvironment.
//The combo box contains objects of the type Font.

to set the selected font to the default system font.

This works most of the time. Although, it appears that for some fonts, the created base font does not match any of the fonts which are retrieved from GraphicsEnvironment.

For me, the base font is Dialog. The name of the font is “Dialog”. However, the names for the fonts retrieved from GraphicsEnvironment for Dialog are “Dialog.Bold”, “Dialog.Plain”, and “Dialog.Italic”. Since the created font has a different name, the combobox will not select the desired item (equals(…) fails).

Note how this works with most fonts (the only one I have tested so far that doesn’t work is the Dialog font).

Is there a better solution to this that avoids this problem? Can I perhaps get the correct font names by using some specific other Swing component than JLabel to get the base font?
Finally, why don’t the names match?

EDIT: Followup question: How does one load a logical fonts physical font? (Making a JComboBox font chooser)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:52:02+00:00Added an answer on May 22, 2026 at 2:52 am

    There are some fonts “Dialog”, “Monospaced” and some more don’t remember names aren’t rel fonts. The artificial fonts are used by java but they are rendered with another physical font. It’s done to provide platform independent font names.

    It means e.g. for “Monospaced” font some OS dependent real font with equal chars’ widhts is used.
    http://download.oracle.com/javase/1.3/docs/guide/intl/addingfonts.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a cross platform application using Swing and Netbeans (Group Layout). Is there
I am creating custom Swing components and want to provide a UI that looks
I am creating a new Widget using the same structure/style as the other Swing
I use the following program for creating JTable using java class. If I get
I am creating line graph using outputs from a thread, the threads are simulations
I am creating a Java Application using netBeans and Swing Gui Builder. I am
I am pretty capable when it comes creating GUIS in Java using Swing, however
I am creating an touch screen application using Swing and have a request to
I am creating an object of another class from my main class using the
Possible Duplicate: Creating online help in Java Swing application - using pdf user docs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.