自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

代碼分享:Swing外觀 抗鋸齒 字體設(shè)置

開發(fā) 后端
這個(gè)是一個(gè)界面顯示效果的處理,Swing中文顯示一直都是不怎么美觀,經(jīng)過修改,比默認(rèn)的好看多了。下文提供代碼。

 [圖片]  默認(rèn)

 [圖片]  使用Nimbus

[圖片]  使用Nimbus并開啟抗鋸齒

 

 [圖片]  使用Nimbus,開啟抗鋸齒并使用自選字體

代碼片段:

  1. package canghailan.ui;  
  2.  
  3. import javax.swing.*;  
  4. import javax.swing.plaf.FontUIResource;  
  5. import java.awt.*;  
  6. import java.util.HashMap;  
  7. import java.util.Map;  
  8.  
  9. /**  
  10.  * @author canghailan  
  11.  * @datetime 2011-12-19 11:13  
  12.  */ 
  13. public class UIs {  
  14.  
  15.     private static final String FALLBACK_FONT_FAMILY_NAME = Font.SANS_SERIF;  
  16.     private static final Map<String, String> FONT_FAMILY_NAMES = new HashMap<>();  
  17.     private static final String[] BEST_FONT_FAMILIES = {  
  18.             "微軟雅黑""arial""sans-serif" 
  19.     };  
  20.     private static final int BEST_FONT_SIZE = 12// 12px  
  21.  
  22.     static {  
  23.         GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();  
  24.         String[] fontFamilyNames = env.getAvailableFontFamilyNames();  
  25.         for (String fontFamilyName : fontFamilyNames) {  
  26.             FONT_FAMILY_NAMES.put(fontFamilyName.toLowerCase(), fontFamilyName);  
  27.         }  
  28.         if (!FONT_FAMILY_NAMES.containsKey("serif")) {  
  29.             FONT_FAMILY_NAMES.put("serif", Font.SERIF);  
  30.         }  
  31.         if (!FONT_FAMILY_NAMES.containsKey("sans-serif")) {  
  32.             FONT_FAMILY_NAMES.put("sans-serif", Font.SANS_SERIF);  
  33.         }  
  34.     }  
  35.  
  36.     public static void enableAntiAliasing() {  
  37.         System.setProperty("awt.useSystemAAFontSettings""on");  
  38.         System.setProperty("swing.aatext""true");  
  39.     }  
  40.  
  41.     public static String getLookAndFeel() {  
  42.         try {  
  43.             for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {  
  44.                 if ("Nimbus".equals(info.getName())) {  
  45.                     return info.getClassName();  
  46.                 }  
  47.             }  
  48.         } catch (Exception ignore) {  
  49.         }  
  50.         return UIManager.getCrossPlatformLookAndFeelClassName();  
  51.     }  
  52.  
  53.     public static String getFontFamily(String[] fontFamilies) {  
  54.         for (String fontFamily : fontFamilies) {  
  55.             fontFamily = fontFamily.toLowerCase();  
  56.             if (FONT_FAMILY_NAMES.containsKey(fontFamily)) {  
  57.                 return FONT_FAMILY_NAMES.get(fontFamily);  
  58.             }  
  59.         }  
  60.         return FALLBACK_FONT_FAMILY_NAME;  
  61.     }  
  62.  
  63.     public static String[] getBestFontFamilies() {  
  64.         return BEST_FONT_FAMILIES;  
  65.     }  
  66.  
  67.     public static int getBestFontSize() {  
  68.         return BEST_FONT_SIZE;  
  69.     }  
  70.  
  71.     /*########################################*/ 
  72.  
  73.     public static void setUI() {  
  74.         enableAntiAliasing();  
  75.         // set LookAndFeel  
  76.         try {  
  77.             UIManager.setLookAndFeel(getLookAndFeel());  
  78.         } catch (Exception ignore) {  
  79.         }  
  80.         // set DefaultFont  
  81.         String bestFontFamily = getFontFamily(getBestFontFamilies());  
  82.         for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {  
  83.             if (entry.getValue() instanceof FontUIResource) {  
  84.                 FontUIResource fontUIRes = (FontUIResource) entry.getValue();  
  85.                 entry.setValue(new FontUIResource(  
  86.                         bestFontFamily,  
  87.                         fontUIRes.getStyle(),  
  88.                         getBestFontSize() > fontUIRes.getSize() ?  
  89.                                 getBestFontSize() : fontUIRes.getSize()  
  90.                 ));  
  91.             }  
  92.         }  
  93.     }  

最新版本:UIs.java

源碼下載:http://down.51cto.com/data/319345

原文鏈接:http://www.oschina.net/code/snippet_116768_7750

【編輯推薦】

  1. Jease 2.6發(fā)布 Java開源內(nèi)容框架
  2. 一個(gè)Java程序員對2011年的回顧
  3. 用Java GUI編寫的畫板程序
  4. Java的動(dòng)態(tài)綁定機(jī)制
  5. Java中帶復(fù)選框的樹的實(shí)現(xiàn)和應(yīng)用

 

責(zé)任編輯:林師授 來源: 開源中國社區(qū)
相關(guān)推薦

2015-09-15 09:20:16

圖片變形抗鋸齒

2009-07-15 10:37:28

Swing外觀

2009-07-10 12:30:12

Swing組件

2009-07-10 15:18:48

Synth外觀Swing外觀

2018-08-06 16:31:36

NVIDIA光線抗鋸齒

2009-06-04 15:52:25

Netbeans6.5字體無法抗鋸齒Ubuntu9.04

2012-05-31 14:11:49

SwingSubstance異常

2012-01-17 17:08:05

JavaSwing

2009-07-14 14:03:56

Swing程序

2009-06-10 17:11:01

linux netbe反鋸齒處理

2010-04-26 16:36:31

DNS負(fù)載均衡設(shè)置

2009-06-10 20:24:17

netbeans my字體設(shè)置

2018-10-18 14:28:33

2009-07-15 09:24:30

Swing動(dòng)態(tài)刷新

2021-08-07 07:59:20

Windows 11操作系統(tǒng)微軟

2009-07-17 16:49:18

lookandfeelSwing

2009-07-14 16:07:59

調(diào)用JavaFX代碼Swing程序

2009-07-14 16:02:04

SWT和Swing

2010-07-08 13:32:17

UDPClient

2009-08-17 07:43:42

Linux命令行安裝字linux命令行安裝彩色字體設(shè)置
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號