Results 1 to 10 of 10
  1. #1
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Original JOptionPane Color

    hi

    I changed my JOptionPane dialog boxes to colors, but i can't figure out how to change them back to the original colors. Also, if someones has a list of all the possible colors that can be used, that would very much be apreciated. thanks


    Java Code:
      Object color = " ";
                Object background = " ";
                UIManager um = new UIManager();
                color = JOptionPane.showInputDialog(null, "Choose a Color for your text", "Menu",
                    JOptionPane.QUESTION_MESSAGE, null, new Object[] { "green" ,"red",
                        "orange", "blue", "black", "yellow", "white" }, "");
                if ( color == "green")
                {
                     um.put("OptionPane.messageForeground", Color.green);
                }
                if ( color =="red" )
                {
                    um.put("OptionPane.messageForeground", Color.red);
                }
                if ( color == "blue")
                {
                    um.put("OptionPane.messageForeground", Color.blue);
                }
                if ( color == "orange")
                {
                    um.put("OptionPane.messageForeground", Color.orange);
                }
                if ( color == "yellow")
                {
                    um.put("OptionPane.messageForeground", Color.yellow);
                }
                if ( color == "white" )
                {
                    um.put("OptionPane.messageForeground", Color.white);
                }
                if ( color == "black")
                {
                    um.put("OptionPane.messageForeground", Color.black);
                }
    
                background = JOptionPane.showInputDialog(null, "Choose a Color for your Background", "Menu",
                    JOptionPane.QUESTION_MESSAGE, null, new Object[] { "green" ,"red",
                        "orange", "blue", "black", "yellow", "white" }, "");
                if ( background == "green")
                {
                     um.put("Panel.background", Color.green);
                }
                if ( background == "red" )
                {
                    um.put("Panel.background", Color.red);
                }
                if ( background == "blue")
                {
                    um.put("Panel.background", Color.blue);
                }
                if ( background == "orange")
                {
                    um.put("Panel.background", Color.orange);
                }
                if ( background == "yellow")
                {
                    um.put("Panel.background", Color.yellow);
                }
                if ( background == "white" )
                {
                    um.put("Panel.background", Color.white);
                }
                if ( background == "black")
                {
                    um.put("Panel.background", Color.black);
                }

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

    Default Re: Original JOptionPane Color

    Quote Originally Posted by jiffi View Post
    Java Code:
                if ( color == "orange")
    Don't try to compare Strings for equality like that; use the equals( ... ) method instead (read th API documentation for the String class). b.t.w. get the color from the object before you change it so you can restore the original color afterwards.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Original JOptionPane Color

    you might want to read this http://download.oracle.com/javase/tu...s/colorchooser.

    And bookmark this The Really Big Index

  4. #4
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Original JOptionPane Color

    @mine 0926
    thanks for your links, though the first one gives me an error 404…

    @Jos So basically, you want me to use if (color.equals("orange")) instead?

    b.t.w. get the color from the object before you change it so you can restore the original color afterwards.
    i'm not sure i follow- i only know basic java, if you could please elaborate, thanks

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

    Default Re: Original JOptionPane Color

    Quote Originally Posted by jiffi View Post
    @mine 0926
    thanks for your links, though the first one gives me an error 404…

    @Jos So basically, you want me to use if (color.equals("orange")) instead?

    I wrote:
    "b.t.w. get the color from the object before you change it so you can restore the original color afterwards. "

    i'm not sure i follow- i only know basic java, if you could please elaborate, thanks
    Yep, the equals method compares two Strings for equality of their content. Read the following pseudo code:

    1) Color originalColor= yourObject.getColor();
    2) change the color of yourObject at will ...
    3) restore the original color: yourObject.setColor(originalColor);

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Original JOptionPane Color

    So in my case, yourObject would be replaced by either OptionPane.messageForeground OR Panel.background??

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

    Default Re: Original JOptionPane Color

    Quote Originally Posted by jiffi View Post
    So in my case, yourObject would be replaced by either OptionPane.messageForeground OR Panel.background??
    yourObject is any object for which you want to change its color and later restore its original color.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    jiffi is offline Member
    Join Date
    Oct 2011
    Posts
    79
    Rep Power
    0

    Default Re: Original JOptionPane Color

    I'm still really confused as to what i need to type for the code. (for what i tried, i get an error message: cannot find symbol - method getColor() )
    Last edited by jiffi; 10-13-2011 at 01:29 PM.

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

    Default Re: Original JOptionPane Color

    Quote Originally Posted by jiffi View Post
    I'm still really confused as to what i need to type for the code. (for what i tried, i get an error message: cannot find symbol - method getColor() )
    I just gave you a bit of pseudo code, nothing to be copied/pasted without giving it a bit of thought ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Original JOptionPane Color

    Quote Originally Posted by jiffi View Post
    @mine 0926
    thanks for your links, though the first one gives me an error 404…
    Here is the correct link: How to Use Color Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

Similar Threads

  1. Close a JFrame, but keep the original open.
    By nolsen01 in forum AWT / Swing
    Replies: 3
    Last Post: 06-13-2011, 11:28 PM
  2. Replies: 9
    Last Post: 05-12-2011, 10:51 PM
  3. Getting to original File location
    By ravjot28 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 04:00 PM
  4. Proxy or Original...!
    By Shiv in forum New To Java
    Replies: 1
    Last Post: 04-11-2009, 03:32 AM
  5. Original Acro looking for Lead Java Programmer
    By Doorsmaniac in forum Jobs Offered
    Replies: 0
    Last Post: 12-20-2007, 01:08 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
  •