• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with TextAttribute.WEIGHT in Java2D  RSS feed

 
padmanabh dongre
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying a program to apply different levels of boldness for a text. i am using the constants in java.swt.font.TextAttribute class to specify the degree of boldness, my problem is that it does not show any effect i.e. it does not change the boldness of the text.
This is the code.
import javax.swing.*;
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
import java.text.*;
public class BoldDemo extends JFrame {
private TextLayout mLayout;
private String str = "Java2D Demo";
private AttributedString as = new AttributedString( str );
BoldDemo( ) {
setSize( 300 , 300 );
setVisible( true );
}
public void paint( Graphics g ) {
Graphics2D g2 = ( Graphics2D ) g;
if( mLayout == null ) {
as.addAttribute( TextAttribute.WEIGHT , TextAttribute.WEIGHT_EXTRABOLD );
mLayout = new TextLayout( as.getIterator( ) , g2.getFontRenderContext( ) );
}
mLayout.draw( g2 , 40 , 80 );
}
public static void main( String cmd[] ) {
BoldDemo b = new BoldDemo( );
}
}
is there anything wrong in the way i have applied the Attribute? or is there any other way to do this ? Please help me
Thanx
Padmanabh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!