I was wondering how to set the default font for my entire Java swing program. From my research it appears it can be done with UIManager
, something to do with LookAndFeel
, but I can't find specifically how to do it, and the UIManager
appears pretty complicated.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I think this is better, calling it for the current laf instead of the whole UIManager put this
Somewhere in the main before instantiating your JFrame object. It worked perfectly for me. Remember this is the default font, for the components that have no specified font.
source: http://www.java.net/node/680725
To solve this problem, I just implement AWTEventListener and listen for COMPONENT_ADDED of ContainerEvent.
All story description at: http://wiki.idempiere.org/en/Swing_Miss_Support_Some_Language
All code at: https://bitbucket.org/hieplq/unicentapos/src/9b22875ab65e26ff46fd9ae62d556b7f64621afa/src-extend/vn/hsv/uitil/font/FontGlyphsUtil.java?at=tip
I'm using Nimbus L&F.
Using code from @Romain Hippeau, I had to use
UIManager.getLookAndFeelDefaults()
instead ofUIManager.getDefaults()
and use the returned reference toput
modified values:For some reason, it does not seem to work with the default L&F... (based on the limited tests I performed)
I used the Synth look and feel XML file and defined the fonts there. Easy, flexible and continent.
You need to create a class with a
createFont
like:And in your synth xml define the font like:
then you may use it as a reference wherever you want in the xml.
none of theses solutions work fine for me, I build my own (stupid) one but it works:
Inspired by Romain Hippeau, use this code if you want to set just the font size.