Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008, 11:33 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
How to use TextAttribute class to change color and font of a text
Code:
import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.font.TextAttribute; import java.text.AttributedString; import javax.swing.JFrame; import javax.swing.JPanel; public class IteratorTest extends JPanel { public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "Java Source and Support"; Dimension d = getSize(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font serifFont = new Font("Serif", Font.PLAIN, 48); Font sansSerifFont = new Font("Monospaced", Font.PLAIN, 48); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, serifFont); as.addAttribute(TextAttribute.FONT, sansSerifFont, 2, 5); as.addAttribute(TextAttribute.FOREGROUND, Color.red, 5, 6); as.addAttribute(TextAttribute.FOREGROUND, Color.red, 16, 17); g2.drawString(as.getIterator(), 40, 80); } public static void main(String[] args) { JFrame f = new JFrame(); f.getContentPane().add(new IteratorTest()); f.setSize(850, 250); f.show(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the color in my program carl New To Java 4 09-19-2008 02:38 PM
How to change color of JTable row having a particular value johnt AWT / Swing 3 09-18-2008 08:28 AM
How to change backgrnd color of link(active) Captainz New To Java 1 05-03-2008 12:10 AM
How to change font/ font color etc in a graphic object using JCombobox? JavaInLove AWT / Swing 0 02-07-2008 12:28 PM
How to change TXT color Onclick dave700800 New To Java 1 12-08-2007 02:39 AM


All times are GMT +3. The time now is 12:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org