Results 1 to 4 of 4
  1. #1
    javan00b is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default window background color?

    How do I set the background color for a window?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    If your window is a JFrame, JDialog or JWindow you can try
    Java Code:
    myFrame.getContentPane().setBackground(yourColor)
    If it is a Frame of Window you can try
    Java Code:
    myRef.setBackground(color)
    JOptionPanes take a little more work.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by hardwired View Post
    If your window is a JFrame, JDialog or JWindow you can try
    Java Code:
    myFrame.getContentPane().setBackground(yourColor)
    Little explanation on this.

    You can do this in this way as well.
    Java Code:
    myFrame.setBackground(yourColor)
    In this way, when you run the application, background color flashes and gone. That is because the frame made up of mane components involving. That's why we used a "Content Pane" in the hardwired code.

  4. #4
    javan00b is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Center background image
    By Floetic in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 05:50 PM
  2. How to make the JTextArea background invisible
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2007, 06:30 PM
  3. Set the background in Java
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:13 AM
  4. Background image in java
    By toby in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 07:15 AM
  5. Why this image background is black ?
    By samson in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 04:24 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
  •