Results 1 to 2 of 2
  1. #1
    chirag123 is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Exclamation Change colour of JOptionPane

    I need to change the colour of a button in a JOptionPane. How my program works is when a button is pressed a JOptionPane appears and displays a message and I need to change the colour of the button text in the JOptionPane. Here's the code for the option pane:

    Java Code:
    UIManager um=new UIManager();
    um.put("OptionPane.background",new ColorUIResource(100,200,255));
    um.put("Panel.background",new ColorUIResource(100,200,255));
    um.put("OptionPane.messageForeground", Color.blue);
    button.titleLabel.textColor = (UIColor blueColor);
    JOptionPane.showMessageDialog(null, "It takes approximately 1 hour and 5 minutes to go from Nottingham to Leicester", "Time", JOptionPane.PLAIN_MESSAGE);
    thanks

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    JOptionPane is a JComponent, so you can use JComponents setBackground() method

    Java Code:
    javax.swing.JOptionPane j = new javax.swing.JOptionPane();
    j.setBackground(Color.red);

Similar Threads

  1. Jtable colour cell problem
    By fuzzdn in forum New To Java
    Replies: 10
    Last Post: 07-30-2011, 06:30 PM
  2. changing JFrame colour
    By simo_mon in forum AWT / Swing
    Replies: 0
    Last Post: 08-08-2009, 03:15 AM
  3. Changing text colour in code
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-29-2009, 04:32 PM
  4. Colour Specific Cell within Table
    By poddy88 in forum New To Java
    Replies: 2
    Last Post: 04-14-2009, 09:20 AM
  5. Replies: 0
    Last Post: 03-26-2009, 02:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •