Why the same font looks different in Java app run from Netbeans and run from Jar?
-
In my Java Swing app I have some JTextAreas, I realize the text looks different when it's run from Netbeans and when the app is run from a Jar file, why ? How to make them look the same ? JTextArea Client_Side_TextArea=new JTextArea(),Network_TextArea=new JTextArea(); setLayout(new BorderLayout()); Client_Side_TextArea.setFont(new Font("Monospaced",0,15)); Client_Side_TextArea.setForeground(new Color(0,28,218)); Client_Side_TextArea.setPreferredSize(new Dimension(290,300)); Client_Side_TextArea.append(" Client Side\n================================\n"); add("West",Client_Side_TextArea); Network_TextArea.setFont(new Font("Monospaced",0,15)); Network_TextArea.setBackground(new Color(226,226,226)); Network_TextArea.setForeground(new Color(0,28,218)); Network_TextArea.setPreferredSize(new Dimension(270,300)); Network_TextArea.append(" Network Connection\n =========================================\n"); add("Center",Network_TextArea); In the following image, the upper part is from the app run with Netbeans, the lower part is how it looks when run from a Jar file :
-
Answer:
This is the expected behavior: as discussed in the https://docs.oracle.com/javase/8/docs/api/java/awt/Font.html API, each supported platform may map a different physical font to a particulate logical font such as Font.MONOSPACED. Each https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html may further refine the choice of font for a particular purpose. Unless the platforms, versions and settings are identical, the fonts may vary. A complete example and more on the mapping may be found http://stackoverflow.com/a/26090878/230513. In addition, for the reasons cited http://stackoverflow.com/q/7229226/230513, don't use setPreferredSize(). If you choose to override getPreferredSize(), be certain not to fall into this http://stackoverflow.com/a/12532237/230513.
Frank at Stack Overflow Visit the source
Related Q & A:
- Why won't my app run in the IOS simulator?Best solution by Stack Overflow
- Why has my font in my e-mail suddenly changed to small?Best solution by Yahoo! Answers
- Why is the font size on Yahoo home page and mail so small?Best solution by Yahoo! Answers
- Why am I having this problem with java or Windows Installer?Best solution by Yahoo! Answers
- Why did the font on my Yahoo pages change?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.