Results 1 to 4 of 4
  1. #1
    Java.child is offline Member
    Join Date
    Sep 2008
    Posts
    32
    Rep Power
    0

    Default How to change string Color

    Hello Experts,

    I am storing some vaule in string.I want if getOptionValue() == 1 then output comes into red color.


    String Priority = "";

    Priot.set( ( new Variant( Frame134.getOptionValue() == 1 ) ) );
    if( Frame134.getOptionValue() == 1 )
    {
    Priority = "Highest Priority";
    }
    Priot.set( ( new Variant( Frame134.getOptionValue() == 2 ) ) );
    if( Frame134.getOptionValue() == 2 )
    {
    Priority = "A-Today";
    }

    Priot.set( ( new Variant( Frame134.getOptionValue() == 3 ) ) );
    if( Frame134.getOptionValue() == 3 )
    {
    Priority = "B-This Week";
    }
    Priot.set( ( new Variant( Frame134.getOptionValue() == 4 ) ) );
    if( Frame134.getOptionValue() == 4 )

    {
    Priority = "C-Next Week";
    }

    Please suggest me how to do that.
    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    String doesn't have a color.

    > then output comes into red color.
    Output where? Console? GUI?

    Please go through this web page:
    How To Ask Questions The Smart Way

    db

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    What you are asking is, "How do I display text in different colors?" The answer depends on how you are displaying the text. If you are creating a Swing GUI, then you could use JLabel or JTextfield and set the appropriate color attributes of those controls.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    OP, please ask your question more clearly next time.

    Quote Originally Posted by Steve11235 View Post
    What you are asking is, "How do I display text in different colors?" The answer depends on how you are displaying the text. If you are creating a Swing GUI, then you could use JLabel or JTextfield and set the appropriate color attributes of those controls.
    Yep, or else use separate font object with required color you want and add it on relevant Swing control.

Similar Threads

  1. Replies: 6
    Last Post: 05-14-2011, 06:48 AM
  2. Change the color in my program
    By carl in forum New To Java
    Replies: 5
    Last Post: 04-03-2009, 12:20 PM
  3. JButton onClick change color background
    By behrk2 in forum AWT / Swing
    Replies: 6
    Last Post: 07-09-2008, 04:54 PM
  4. How to change backgrnd color of link(active)
    By Captainz in forum New To Java
    Replies: 1
    Last Post: 05-02-2008, 11:10 PM
  5. How to change TXT color Onclick
    By dave700800 in forum New To Java
    Replies: 1
    Last Post: 12-08-2007, 01:39 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
  •