Results 1 to 14 of 14
  1. #1
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Question [SOLVED] how to cahnge the background color of the frame?

    hi all,
    can anyone please tell me how can i change the background color of my form. I am developing a desktop application using NetBeans IDE.

    can i use any image/icon as the icon for th frame? if yes, how?


    thanks in advance!

    regards
    Thanks and Regards,
    Pranav

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    1. One way: change the background color of a JPanel using setBackground(...) and set that JPanel as the contentPane of the JFrame.

    2. JFrame#setIconImage(...)

    db

  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 pranav13 View Post
    can i use any image/icon as the icon for th frame? if yes, how?
    Yes you can. Did you search on the web?

    Java Code:
            ImageIcon imageBack = new ImageIcon(image_goes_here);
            JLabel background = new JLabel(imageBack);
            background.setBounds(0, 0, imageBack.getIconWidth(), imageBack.getIconHeight());
    	getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
            jPanel1.setOpaque(false);
            setContentPane(jPanel1);

  4. #4
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    how can i replace the java icon with my icon in a JFrame.
    I am using NetBeans IDE.

    pls tell me.
    Thanks and Regards,
    Pranav

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

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    Eranga, I think pranav13 is referring to the title bar icon. The answer to that is at #2, and shouldn't have anything to do with the choice of IDE :)

    db

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

  8. #8
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    hey, sry i hv clubbed 2 questions n confused u.
    i gt the solution from bruke`s suggestion.
    Actually, i was trying to set the icon property of the form in properties window in NetBeans IDE. But it is not setting. Thats why i have written it manually using setIconImage().

    Thanks for your suggestions!
    Thanks and Regards,
    Pranav

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    Well there is also a property IconImage (and also IconImages) that can be set from the NetBeans property list. But looking at it, it's easier to just write the code yuorself :)

    As in the case of many other features of the Visual Editor.

    db

  10. #10
    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

    I think write code your self is the best. Even that the above code segment I've written on NetBeans.

  11. #11
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    thanks darryl bruke!
    i got one more problem. I am running a Process in a background thread. and i want to stop that process when i click a button.
    i cudnt access the obj of Process from the button click event. i also tried to declare it as static but in vain.
    pls suggest me possible workarounds.
    Thanks and Regards,
    Pranav

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    Umm, I think you should post a fresh topic for that. And to have a chance of getting good responses, you need to follow the advice here:
    How To Ask Questions The Smart Way

    db

  13. #13
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    ok bruke.
    i ll post it in a new post.
    thank you.
    Thanks and Regards,
    Pranav

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

Similar Threads

  1. How to Run a .exe in background???
    By jazz2k8 in forum New To Java
    Replies: 9
    Last Post: 01-21-2011, 11:27 AM
  2. BackGround & ForeGround
    By hungleon88 in forum Advanced Java
    Replies: 3
    Last Post: 08-31-2008, 07:20 AM
  3. setting background color of JFrame form with NetBeans 6.1
    By onefootswill in forum New To Java
    Replies: 4
    Last Post: 08-12-2008, 07:02 AM
  4. JButton onClick change color background
    By behrk2 in forum AWT / Swing
    Replies: 6
    Last Post: 07-09-2008, 04:54 PM
  5. window background color?
    By javan00b in forum New To Java
    Replies: 3
    Last Post: 01-29-2008, 10:43 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
  •