Results 1 to 6 of 6

Thread: How Can I Change the background Color Of A JOptionPane?

  1. #1
    Join Date
    Nov 2009
    Posts
    712

    How Can I Change the background Color Of A JOptionPane?

    Hello, I am beginner in Java and I have written the program in it. Now, I want to set the background color of the JOptionPane. But, I don't know how to do it. If anyone is having idea about it, then please tell me how to do it. Please, reply me with the code which will help me for the setting background of the JOptionPane.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How Can I Change the background Color Of A JOptionPane?

    Hello, I have a small code which can simply help you while changing the background of the JOptionPane.

    Code:
    UIManager.could("OptionPane.background", Color.blue);
    UIManager.could("Panel.background", Color.blue);
    Just make use of it and solve your problem.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How Can I Change the background Color Of A JOptionPane?

    Hey, see the code below which I have got on internet. From the code below you can abel to set a JOptionPane's background, including his children :

    Code:
    public static void setback(JOptionPane JP, Color clr) 
    {
    JP.setBackground(clr);
    for (Iterator i = getComponents(JP).iterator(); i.hasNext(); ) 
    {
    Component cmp = (Component)i.next();
    if (cmp instanceof JPanel) 
    {
    cmp.setBackground(clr);
    }
    }
    }
    public final static Collection getComponents(Container cntr) 
    {
    Collection cmponents = new Vector();
    Component[] cmp = cntr.getComponents();
    for (int i = 0, n = cmp.length; i < n; i++) 
    {
    cmponents.add(cmp[i]);
    if (cmp[i] instanceof Container) 
    {
    cmponents.addAll(getComponents((Container) cmp[i]));
    }
    }
    return cmponents;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How Can I Change the background Color Of A JOptionPane?

    This is quiet simple to change the background color of the JOtionPane. You can simply make use of the code below which will help you to get the the background changed:
    Code:
    import javax.swing.JOptionPane;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    public class Background 
    {
    public static void main(String[]args)
    {
     UIManager UI=new UIManager();
     UI.put("OptionPane.background",new ColorUIResource(255,0,0));
     UI.put("Panel.background",new ColorUIResource(255,0,0));
    
     JOptionPane.showMessageDialog(null,"Techanera.in","Forum", JOptionPane.INFORMATION_MESSAGE);
    }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How Can I Change the background Color Of A JOptionPane?

    Hello, I think you may need to make use of the code below for getting your Background of the JOptionPane changed. Just make use of it and solve the problem:
    Code:
    import java.awt.*;
    import javax.swing.*;
    public class Bkcolor
    {
    public static void main(String[]args)
    {
     UIManager UManager=new UIManager();
     UManager.put("OptionPane.background",Color.red);
     UManager.put("Panel.background",Color.red);
     JOptionPane.showMessageDialog(null,"Hello","Set Color", JOptionPane.INFORMATION_MESSAGE);
    }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How Can I Change the background Color Of A JOptionPane?

    Hello, It may be possible to set the background of the JOptionPane. So, you just need to make use of the object of the UIManager class and then you can simply able to take help of the put() method to change the background of the JOptionPane.
    Code:
    UIManager.put("OptionPane.background", Color.blue);
    UIManager.put("Panel.background", Color.blue);

Similar Threads

  1. change Metro background color on windows 8
    By Naila in forum Customize Desktop
    Replies: 1
    Last Post: 09-08-2012, 07:30 PM
  2. Unable to change background color of PDF file
    By GurdeepS in forum Windows Software
    Replies: 4
    Last Post: 12-03-2010, 07:22 PM
  3. Change The Background Color Of The Jsp
    By rashmi_ay in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 08:22 PM
  4. Change the background color of QTextEdit
    By Gomeler in forum Software Development
    Replies: 3
    Last Post: 27-11-2009, 01:13 PM
  5. How to change background color scheme in MSN messenger?
    By Rahman Khan in forum Windows Software
    Replies: 3
    Last Post: 28-03-2009, 05:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,824,430.96655 seconds with 16 queries