문제

My code uses getFontMetrics() which is deprecated. What could be the alternative ?

    public void setFont ( Font font ) {
       if(font == null){
           Font defaultFont=(Font)javax.swing.UIManager.getDefaults().get ( "Label.font" ) ;
           font=new Font(defaultFont.getName(),Font.BOLD,defaultFont.getSize()+8);;
       }
      FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics (font) ;
      fontHeight      = fontMetrics.getHeight() ;
      fontDescent     = fontMetrics.getDescent() ;
      fontLeading     = fontMetrics.getLeading() ;
      if ( text != null ) 
         fontWidth = Toolkit.getDefaultToolkit().getFontMetrics (font).stringWidth ( text ) ;
      currentFont = font ;
      super.setFont ( font ) ;
   }

Any suggestions ?

도움이 되었습니까?

해결책

The Javadoc tells you

As of JDK version 1.2, replaced by the Font method getLineMetrics.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top