Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to change font in java using Swing?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-11-2009
Member
 
Join Date: Nov 2008
Posts: 85
How to change font in java using Swing?
  

Hello friends, I am new in programming and currently working on java. Currently I want to change my font of the text which is by default "Times New Roman". I want to change it as "Monotype Corsiva". Can anyone provide me method which can help me? I am waiting for your reply. Please reply me within this day, as I really need it urgently.

Reply With Quote
  #2  
Old 17-11-2009
Member
 
Join Date: May 2008
Posts: 2,001
Re: How to change font in java using Swing?

Hi, you want to change font color. Then you can try setFont() method I think. I have learned java one year back and need to revise it. But, If I am not wrong then this is a method which is used for the changing font color. Just try to use it. Currently I am in the office and when I will go to the home I will confirm it whether it is right or wrong. Just check on google regarding it. You will find out it on it. Just check it.
Reply With Quote
  #3  
Old 17-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,993
Re: How to change font in java using Swing?

Hi, for setting font in java setFont() method has been used. You can provide it font object as its operand and try it. For more information you can check it in Java 2 Complete Reference and get more information related to it. You can get more help from java official site such as sun.com. I think you just need to change font of the text, then just use that method and solve your problem.
Reply With Quote
  #4  
Old 17-11-2009
Member
 
Join Date: May 2008
Posts: 2,283
Re: How to change font in java using Swing?

Hi, I am giving you example for changing font of the string. Just use it. In this example setFont() method has been used to set font of the string to which you want. Just understand it and then use it as you want.

import java.applet.*;
import java.awt.*;
//<applet code="Appf1.class" width=200 height=200></applet>
public class SetFontWhichWant extends Applet
{
Font Mono;
public void init()
{
setBackground(Color.red);
Mono=new Font("Monotype Corsiva",Font.PLAIN,30);
}
public void paint(Graphics g)
{
g.setFont(Mono);
g.setColor(Color.black);
g.drawString("My Font Which I want",10,20);
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to change font in java using Swing?"
Thread Thread Starter Forum Replies Last Post
Applets V/s Swing in JAVA "Dritan" Software Development 3 14-12-2010 08:04 AM
Print in java using Swing Sheenas Software Development 3 18-11-2009 08:50 AM
Java Swing and MySQL shelton141 Software Development 1 22-09-2009 08:50 AM
drawPolygon in java Swing? JagdishP Software Development 3 07-08-2009 11:33 PM
Java swing help with repaint() grudge Software Development 4 23-07-2009 03:41 PM


All times are GMT +5.5. The time now is 02:37 PM.