aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes Problem with TextAttribute.WEIGHT in Java2D Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "Problem with TextAttribute.WEIGHT in Java2D" Watch "Problem with TextAttribute.WEIGHT in Java2D" New topic
Author

Problem with TextAttribute.WEIGHT in Java2D

padmanabh dongre
Greenhorn

Joined: Aug 13, 2001
Posts: 24
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
 
IntelliJ Java IDE
 
subject: Problem with TextAttribute.WEIGHT in Java2D
 
Threads others viewed
Printing Database Records to an external printer/paper?
JComponent Color
JComponent Color
Problem with drawing styled (attributed) text
IntelliJ Java IDE