سؤال

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