Reputation: 1
I am building Swing GUIs in NetBeans 13, and the default font shown is Segoe UI 12 Plain:
I can select the ellipses and change the font of course, but having to do this for every component in the user interface is tiresome.
Where is this font stored as the default? It must be in NetBeans somewhere, as it appears each time I add a component to a panel. I really need to do this so every time I run NetBeans and add a Swing component to a GUI it defaults to something else (it will be Calibri 14 point if it makes a difference).
Actually selecting the ellipses brings up a dialogue box to amend the font...
As you can see, there is an option to "Derive the font from the default font", so there is a default font stored somewhere, but I cannot find it at anywhere in Tools > Options, nor is it obvious from a Google search.
It's so frustrating! All I want is for the user interfaces I create to appear using the Calibri 14 font, not the Segoe font, without having to amend each occurrence individually in the designer.
I am porting this specific application and UI from C# in Visual Studio to make it easier to run on a spare machine that I can put Linux on, not just Windows, but it is this kind of frustrating, petty problem that is giving me second thoughts.
A code-based solution is unacceptable, as this would need to be included for each application I develop.
Any help would be appreciated, thank you.
Upvotes: 0
Views: 554
Reputation: 1422
Netbeans GUI Builder does not have its own UI settings. The GUI Builder Properties windows just displays the default value of the current look & feel (i.e. the font value which is used by Java when you call new JLabel()
without specifying a font). You can verify the generated code in the initComponents()
method: a JLabel.setFont(xxx)
statement will be generated only if you alter the font in the Properties window.
Remember that the default font will change depending on the look & feel (your program will not look the same on Windows and Mac). That's why in general, for maximum portability, it's better if you can rely on the default font.
The derive font feature lets you rely on the default font but with some modification (bold, italic, bigger, smaller).
So how to change the default font for all your UI ?
You need to do it programmatically using UIManager
and UIDefaults
. For example the line below changes the default font for all JLabel instances.
UIManager.getLookAndFeelDefaults().put("Label.font", new Font("Arial", Font.PLAIN, 30));
JLabel myLabel = new JLabel(); // Will use Arial Plain 30
See this post to get the list of available UI properties: List of Java Swing UI properties?
Upvotes: 1