Total members 11895 |It is currently Tue Dec 03, 2024 6:44 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





code for change Font of text in java
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 86641 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Nice
I got a lot of stuff with this, thanks!



Author:
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : change Font of text in java
 Change the td font style     -  
 change the font style of the body tag     -  
 change font size in JavaScript     -  
 Control font size of sub and sup text     -  
 Change the link font family and weight     -  
 how to change the alignment text in html     -  
 change the direction of text in your page     -  
 Change the text indent in the paragraph     -  
 Forum Description Text color change - Need Help     -  
 Outlining the font in java     -  



Topic Tags

Java Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com