Results 1 to 4 of 4

Thread: How to change font in java using Swing?

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,015

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,302

    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);
    }
    }

Similar Threads

  1. Applets V/s Swing in JAVA
    By "Dritan" in forum Software Development
    Replies: 3
    Last Post: 14-12-2010, 08:04 AM
  2. Print in java using Swing
    By Sheenas in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 08:50 AM
  3. Java Swing and MySQL
    By shelton141 in forum Software Development
    Replies: 1
    Last Post: 22-09-2009, 08:50 AM
  4. drawPolygon in java Swing?
    By JagdishP in forum Software Development
    Replies: 3
    Last Post: 07-08-2009, 11:33 PM
  5. Java swing help with repaint()
    By grudge in forum Software Development
    Replies: 4
    Last Post: 23-07-2009, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •