Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 4:44 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Code Snippet
 Code subject: change Font of text in java
PostPosted: Tue Nov 11, 2008 8:59 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

code for change Font of text in java
Code:
import java.awt.*;
import java.text.*;
import javax.swing.*;
import java.awt.font.*;

public class ShowColorAndFont extends JPanel {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    String text = "Java is an Object Oriented Programming Language.";
    Dimension dimension = getSize();

    Font font1 = new Font("Book Antiqua", Font.PLAIN, 30);
    Font font2 = new Font("Monotype Corsiva", Font.PLAIN, 30);

    AttributedString attributedString = new AttributedString(text);
    attributedString.addAttribute(TextAttribute.FONT, font1);
    attributedString.addAttribute(TextAttribute.FONT, font2, 1, 4);
  attributedString.addAttribute(TextAttribute.FONT, font2, 6, 7);
  attributedString.addAttribute(TextAttribute.FONT, font2, 9, 10);
  attributedString.addAttribute(TextAttribute.FONT, font2, 12, 17);
  attributedString.addAttribute(TextAttribute.FONT, font2, 19, 26);
  attributedString.addAttribute(TextAttribute.FONT, font2, 28, 38);
  attributedString.addAttribute(TextAttribute.FONT, font2, 40, 47);

  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 0, 1);
    attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 5, 6);
  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 8, 9);
  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 11, 12);
  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 18, 19);
  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 27, 28);
  attributedString.addAttribute(TextAttribute.FOREGROUND, Color.red, 39, 40);
   
    g2d.drawString(attributedString.getIterator(), 40, 80);
  }
  public static void main(String[] args) {
    JFrame frame = new JFrame("Show Color and Font");
    frame.getContentPane().add(new ShowColorAndFont());
    frame.setSize(700, 200);
    frame.show();

  }


Attachments:
File comment: change font in java
colorFont.gif
colorFont.gif [ 8.69 KiB | Viewed 44018 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
 Code subject: Re: change Font of text in java
PostPosted: Sat Feb 04, 2012 4:35 pm 
Nice
I got a lot of stuff with this, thanks!


TOP
  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Search records from text file
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team