2014-01-10 2 views
3

JButton 텍스트 내에서 다른 글꼴 패밀리를 얻을 수 있습니다. 그것은 다음과 같습니다다른 사용자 글꼴이있는 JButton 텍스트

JButton button = new JButton("<html><font face=Arial>Hello </font><font face=Verdana>World</font></html>"); 

아래처럼. "안녕하세요"와 Arial, "세계"와 Verdana. 나는 단어가 내가 Font.createFont() 방법을 사용하여 만든 글꼴을하려면 무엇을

enter image description here

하지만. 나는 이와 같은 어떤 것이 효과가있을 것이라고 생각했다.

Font myFont = createMyFont(); 
JButton button = new JButton("<html><font face=MyFont>Hello </font>World</html>"); 

이 질문의 중요성은 내가 하나의 JButton에 두 개의 글꼴이 다국어 소프트웨어를 작성하고 있다는 점이다. 그것은이처럼,

enter image description here

:하지만

enter image description here

+0

Javadoc가 ' –

+0

폰트 등록 시도 Font.createFont()'를 사용하여 만든 후 글꼴'Font.registerFont()를 사용하여 언급한다) ( 'GraphicsEnvironment의 GE = GraphicsEnvironment.getLocalGraphicsEnvironment 단계; \t ge.registerFont (myFont); ' –

+0

그리고 어떤 이름에서 불러야합니까? 그 파일 이름? – Akshat

답변

2

등록 사용자 정의 글꼴 :

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment() 
ge.registerFont(myFont); 

그래서, 난 내 JButton이처럼되고 싶어요

이후 -> 세부 사항을 거기는 제목의

 URL fontUrl; 
     try { 
      fontUrl = new URL("http://www.webpagepublicity.com/" + 
        "free-fonts/a/Airacobra%20Condensed.ttf"); // dummy font 

      Font myFont = Font.createFont(Font.TRUETYPE_FONT, fontUrl.openStream()); 
      myFont = myFont.deriveFont(Font.PLAIN,20); 
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
      ge.registerFont(myFont); 


      button.setText("<html><font face='Airacobra Condensed'>Hello </font>World</html>"); 

     } catch (MalformedURLException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } catch (FontFormatException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

파일 이름는 글꼴 파일을 rightclicking 속성을 선택하여 창에 accquired 할 수 있습니다, 파일 이름, 같은 것을 제공합니다. 예 : FontAwesome Regular.

enter image description here

관련 문제