JOption Dialog and color...

Discussion in 'Java' started by sanna, Jan 24, 2006.

  1. sanna

    sanna Guest

    Hi,

    In a part of my program I am openeing an error warnign as following:

    if (myVal != yourVal) {

    JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
    yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);

    }

    But I need that message "WARNING: \n MyVal does NOT yourVal" printed
    out in red color. and currently its printing in black. Any suggestions?

    Thanks,

    ecoswiss
     
    sanna, Jan 24, 2006
    #1
    1. Advertising

  2. sanna

    Vova Reznik Guest

    sanna wrote:
    > Hi,
    >
    > In a part of my program I am openeing an error warnign as following:
    >
    > if (myVal != yourVal) {
    >
    > JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
    > yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);
    >
    > }
    >
    > But I need that message "WARNING: \n MyVal does NOT yourVal" printed
    > out in red color. and currently its printing in black. Any suggestions?
    >


    Use HTML.
    "<HTML><FONT color=\"red\">WARNING:<BR>MyVal does NOT yourVal</FONT></HTML>"

    > Thanks,
    >
    > ecoswiss
    >
     
    Vova Reznik, Jan 24, 2006
    #2
    1. Advertising

  3. sanna

    Oliver Wong Guest

    "sanna" <> wrote in message
    news:...
    > Hi,
    >
    > In a part of my program I am openeing an error warnign as following:
    >
    > if (myVal != yourVal) {
    >
    > JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
    > yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);
    >
    > }
    >
    > But I need that message "WARNING: \n MyVal does NOT yourVal" printed
    > out in red color. and currently its printing in black. Any suggestions?


    Parts of Swing allow you to use HTML. I haven't tried it with
    JOptionPane, but I suppose it's worth a shot.

    <code>
    JOptionPane.showMessageDialog(null,"<font color='#FF0000'>WARNING: \n MyVal
    does NOT yourVal.</font>","Error Dialog",JOptionPane.ERROR_MESSAGE);
    </code>

    Alternatively, you could manually create a dialog, and put in a JLabel
    set to whatever color you want. See
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDialog.html#JDialog()

    - Oliver
     
    Oliver Wong, Jan 24, 2006
    #3
  4. sanna

    Vova Reznik Guest

    Oliver Wong wrote:
    > "sanna" <> wrote in message
    > news:...
    >
    >>Hi,
    >>
    >>In a part of my program I am openeing an error warnign as following:
    >>
    >>if (myVal != yourVal) {
    >>
    >> JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
    >>yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);
    >>
    >> }
    >>
    >>But I need that message "WARNING: \n MyVal does NOT yourVal" printed
    >>out in red color. and currently its printing in black. Any suggestions?

    >
    >
    > Parts of Swing allow you to use HTML. I haven't tried it with
    > JOptionPane, but I suppose it's worth a shot.
    >
    > <code>
    > JOptionPane.showMessageDialog(null,"<font color='#FF0000'>WARNING: \n MyVal
    > does NOT yourVal.</font>","Error Dialog",JOptionPane.ERROR_MESSAGE);
    > </code>
    >
    > Alternatively, you could manually create a dialog, and put in a JLabel
    > set to whatever color you want. See
    > http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDialog.html#JDialog()
    >
    > - Oliver
    >
    >

    Or :)
    UIManager.put("OptionPane.messageForeground", Color.RED);
    After using that you'd better set Color back to its original.

    Or ...
     
    Vova Reznik, Jan 24, 2006
    #4
  5. sanna

    sanna Guest

    > Or :)
    > UIManager.put("OptionPane.messageForeground", Color.RED);
    > After using that you'd better set Color back to its original.
    >
    > Or ...


    Using
    UIManager.put("OptionPane.messageForeground", java.awt.Color.red);

    I get message: Cannot resolve symbol
    symbol: variable UIManager

    Do I need to defien it somewhere?
    Using html chanegs the color but font size and style is totally
    changed from other dialog messages......
    Which looks a bit funny....
    any suggestions?

    Thanks a lot!
     
    sanna, Jan 24, 2006
    #5
  6. sanna

    Vova Reznik Guest

    sanna wrote:
    >>Or :)
    >>UIManager.put("OptionPane.messageForeground", Color.RED);
    >>After using that you'd better set Color back to its original.
    >>
    >>Or ...

    >
    >
    > Using
    > UIManager.put("OptionPane.messageForeground", java.awt.Color.red);
    >
    > I get message: Cannot resolve symbol
    > symbol: variable UIManager
    >
    > Do I need to defien it somewhere?
    > Using html chanegs the color but font size and style is totally
    > changed from other dialog messages......
    > Which looks a bit funny....
    > any suggestions?
    >
    > Thanks a lot!
    >


    You'd better to use HTML, but
    javax.swing.UIManager
     
    Vova Reznik, Jan 24, 2006
    #6
  7. sanna

    IchBin Guest

    sanna wrote:
    >> Or :)
    >> UIManager.put("OptionPane.messageForeground", Color.RED);
    >> After using that you'd better set Color back to its original.
    >>
    >> Or ...

    >
    > Using
    > UIManager.put("OptionPane.messageForeground", java.awt.Color.red);
    >
    > I get message: Cannot resolve symbol
    > symbol: variable UIManager
    >
    > Do I need to defien it somewhere?
    > Using html chanegs the color but font size and style is totally
    > changed from other dialog messages......
    > Which looks a bit funny....
    > any suggestions?
    >
    > Thanks a lot!
    >

    You need this import

    import javax.swing.UIManager;



    --

    Thanks in Advance...
    IchBin, Pocono Lake, Pa, USA
    http://weconsultants.servebeer.com/JHackerAppManager
    __________________________________________________________________________

    'If there is one, Knowledge is the "Fountain of Youth"'
    -William E. Taylor, Regular Guy (1952-)
     
    IchBin, Jan 24, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miller_Man

    JOption Pane/ How to check string

    Miller_Man, Dec 2, 2004, in forum: Java
    Replies:
    6
    Views:
    7,733
    Miller_Man
    Dec 2, 2004
  2. yw
    Replies:
    3
    Views:
    834
    Phlip
    Jul 2, 2005
  3. mamta81

    JOption PAne

    mamta81, May 22, 2008, in forum: Java
    Replies:
    2
    Views:
    673
    RedGrittyBrick
    May 22, 2008
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    446
    Kamaljeet Saini
    Feb 13, 2009
  5. Matt
    Replies:
    1
    Views:
    290
    Randy Webb
    Nov 20, 2004
Loading...

Share This Page