Results 1 to 3 of 3
  1. #1
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Changing text colour in code

    On the press of the help button this code is running

    Java Code:
    if(evt.getSource()==cmdHelp);
                    {
                     optPane1.showMessageDialog(this,                        
                        " You can use your mouse or tab key to navigate\n"+
                        " our body mass calculator.\n\n"+
                        " New button, this will overwrite all previous\n" +
                        " files\n\n"+
                        " Add Record, enables you to add a new member\n" +
                        " to the records only after creating new file.\n\n"+
                        " Search button, enter your membership number \n" +
                        " click search to find member details.\n\n"+
                        " Update Button, Search for the appropriate record\n"+
                        " by membership number, amend the details\n"+
                        " then click the update button\n\n"+                    
                        " Select Imperial or Metric for the measurements,\n" +
                        " enter the height and weight then click convert\n\n"+
                        " The default measurements are metric, if you \n"+
                        " select imperial using the radio button you \n"+
                        " will be advised."+
                        " \n","User Guide",optPane1.INFORMATION_MESSAGE);}
    As usual the text is black, however I wondered if it was possible to change the following only to red leaving the rest black

    Java Code:
    New button, this will overwrite all previous\n" +
                        " files\n\n"+
    Thanks in advance

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

    Default

    First, I assume optPane1 is some sort of JOptionPane. Good practice says to invoke static methods using the class name, not through an instance.

    You can use JOptionPane.showOptionDialog to display any sort of JComponent in the message parameter. You could build your message in a JPanel using JLabel's and set some of the JLabel's color to red. Or, you could use one of the fancier text components and make it read-only. Essentially, you have a lot of options.

  3. #3
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    You should be able to manipulate the string with html...

    Java Code:
    String myString="<html><body><font color=red>This is some red text...</font></body></html>";
    
    .
    I am pretty sure that you can do this for any text that goes into a component... I use it alot for my tooltips...
    Last edited by markw8500; 04-29-2009 at 03:46 PM.
    Who Cares... As Long As It Works...

Similar Threads

  1. Replies: 0
    Last Post: 03-26-2009, 01:23 AM
  2. manual BMP rendering colour issues
    By Goseph in forum AWT / Swing
    Replies: 0
    Last Post: 02-24-2009, 08:26 PM
  3. POI changing text to a form label
    By natt in forum Advanced Java
    Replies: 2
    Last Post: 09-19-2008, 10:49 AM
  4. Changing the color of text
    By Lang in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 09:51 AM
  5. Changing plugins source code
    By yakupemre in forum Eclipse
    Replies: 1
    Last Post: 08-15-2007, 09:31 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
  •