Results 1 to 3 of 3

Thread: font color

  1. #1
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Question font color

    I'd like to define a font ( face, style, size, and color) once at the beginning of my program, then apply it to my text components.

    I have taken care of the font face, style, and size with

    Font font = new Font( "chalkboards", Font.PLAIN, 24);

    How do I set the color as well?

    If these is a better way to do all these tasks, I'd love to know.

    Thanks a million!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by newbie123 View Post
    I'd like to define a font ( face, style, size, and color) once at the beginning of my program, then apply it to my text components.

    I have taken care of the font face, style, and size with

    Font font = new Font( "chalkboards", Font.PLAIN, 24);

    How do I set the color as well?

    If these is a better way to do all these tasks, I'd love to know.

    Thanks a million!
    A color is not a font attribute (e.g. you can draw an 'A' in red or in blue) so you have to setForeground( ... ) the color of every JComponent (or any class extending it) when you want to draw text in a specific color.

    kind regards,

    Jos

  3. #3
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default thanks

    Thanks for your clarification. I played around with both setBackground() and setForeground(), and I seem to get how they work. It seems like a kind of strange way to do something so simple, but I'm new to Java and I'll wait and see.

Similar Threads

  1. Changing println font color
    By xcallmejudasx in forum New To Java
    Replies: 4
    Last Post: 05-21-2009, 05:05 PM
  2. Replies: 5
    Last Post: 04-25-2009, 09:00 PM
  3. to set toolItem font color
    By vidyakkk in forum SWT / JFace
    Replies: 0
    Last Post: 01-30-2009, 04:06 PM
  4. Replies: 6
    Last Post: 01-02-2009, 10:36 PM
  5. Disabled JButton font color
    By p900128 in forum Advanced Java
    Replies: 1
    Last Post: 07-24-2008, 09:16 AM

Posting Permissions

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