Making a label background change

I use this code now but it dunna work...
what am i doing wrong?
// Label Online : Red when not in contract, blue when in contract.
l_online.setBackground(Color.red);
l_online.setForeground(Color.black);
l_online.setText("Online");
gbc_contr.gridx = 0;
gbc_contr.gridy = 0;
gbc_contr.insets = new Insets(15, 25, 0, 5);
gb_contr.setConstraints(l_online, gbc_contr);
contr_client.add(l_online);

Hi,
If I've got you right, you want to change the background color of your label according to a value..
say when value=0, you make the bgcolor red, otherwise, it is blue...
label.setBackground(Color.red) works when you say
label.setOpaque(true).
I think it is false, by default.
Here is a code sample...
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class Test extends JFrame
     JLabel label;
     Test()
          getContentPane().setLayout(new BorderLayout());
          getContentPane().setBackground(Color.black);
          label = new JLabel("Data");
          getContentPane().add(label,BorderLayout.NORTH);
          setSize(200,200);
          setVisible(true);
          int value=0;
          label.setOpaque(true); //Note this
          System.out.println(label.isOpaque());
          while(true)
               if(value == 0)
                    System.out.println("RED");
                    label.setBackground(Color.red);
               else
                    System.out.println("BLUE");
                    label.setBackground(Color.blue);
               try
                    Thread.sleep(2000);
               catch(InterruptedException ie){}
               value=(value==0)?1:0;
     public static void main(String args[])
          Test test = new Test();
}

Similar Messages

  • Default UITableViewCell text label background color

    I need a table view cell that just has simple text but with custom backgroundView images when not selected vs. selected. I'm too lazy to implement a custom cell, so I was using the regulation UITableViewCell, setting the backgroundView and backgroundSelectedView. The problem is for non-white backgroundView, when the cell is not selected, the text has a white box around it (the background color of the label containing the text, I assume), which looks horrible. When the cell is selected, the default UITableViewCell implementation takes care of changing the text color to white and text label background to clearColor and the custom backgroundSelectedView shows through beautifully. Is there a reason why the text label shouldn't just have a clear background color ALL THE TIME?? If the UITableViewCell is not customized for backgroundView, i.e., the cell background is white, the clear colored text label is no different from a white colored text label. If the backgroundViews are customized to non-white, a clear text label won't be in the way of the backgroundView showing through.
    Does this sound like a good feature request?
    How does one submit requests or bug reports for iPhone SDK anyways??
    Thanks.

    fitzyjoe wrote:
    I am having this exact same problem right now. Did you have to subclass UITableViewCell to fix it?
    I had the same problem and subclassed UITableViewCell to solve it. I set the backgroundView and selectedBackgroundView to UIView instances I wanted to use and then implemented setSelected:animated: in my subclass.
    {code:}
    -(void)setSelected:(BOOL)selected animated: (BOOL)animated {
    [super setSelected: selected animated: animated];
    for (UIView *view in self.contentView.subviews) {
    view.backgroundColor = [UIColor clearColor];
    {code}
    Bit bruteforce and as Apple suggests this will impact table performance, but the tables I work with aren't that big and it works well so far.
    It'd be nice if UITableViewCell honored backgroundView like it does selectedBackgroundView, i.e. when the backgroundView property is set keep the cell contents transparent.

  • My Mac's background changed to white and i can't change it back

    Dear anybody,
    Yesterday I plugged in my external harddisk, and I just moving some folders from one partition to another. then in the middle of progress, it opened an error window and the external hd disappeared from my desktop icon and finder. I tried to plugged out and plugged in again but it's not recognized until I restarted it. and the process of restarting takes about 5minutes (it's not usual since I just need about 30-60secs to reboot my mac). then I logged in and my background changed to white. I thought it was missing my bg pict, then I searched for the picture and set it again as desktop background but nothing happened. it's still white. but the strange is when I press f9 or f10 button (expose), I saw the picture on my background and a lot of windows exposed, then when I click one of the window, it disappeared again, changed to white.
    so, please anybody who had ever gotten this kinda problem, help me out. Thanks for your attention!
    *Leopard-10.5

    ''david.abel wrote:''
    On the Firefox home page, the Arabic language has suddenly started to appear
    Is the language for the menus and other user interface elements still English? If so,
    # Click the ≡ Menu Button and choose Preferences.
    # Click the Content icon.
    # Below Languages, click the Choose button.
    # Make sure a specific variant of English like ''en-us'' is at the top, followed by ''en''. Remove any unwanted languages as well.
    [[Settings for fonts, languages, pop-ups, images and JavaScript|Settings for fonts, languages and pop-ups]]
    ''david.abel wrote:''
    Also, my browser history has started to take up part of the screen.
    I don't know what you mean by that. Please attach a screenshot.
    * [[How do I create a screenshot of my problem?]]

  • Background Change Picture Feature Not Working

    I have had my macbook pro for about 6 months now and my change background feature worked fine when I first got it. I could add folders of pictures and tell it change ever 5 seconds and it worked. Over time, I messed with my dock settings and background settings with other third party programs and stuff and decided I didn't like them so I would just go back to the features built into Leopard. I tried to do a random, change every 5 seconds background change folder deal the other day and it never would change. I tried doing it on the default folders like the apple images and the nature ones and stuff but it would never change. I can still add folders. I can click the option of random order and change every x times. When I close out my system preferences, it resets what I did. I go back to my background panel and they are unchecked. How can I fix this and is anyone else having this problem?

    delete the file com.apple.desktop.plist from homedirectory/Library/Preferences and log out/in. You background settings should be set to defaults and you should be able to change them as you like.

  • Background changes for every button?

    Hello, I am using encore 5.1 and I was wondering if it's possible to have the background change every time I go from one button to the next withtout actually changing menus?
    I would like to do something like in the video I'm linking (watch only the first 10 seconds to get an idea of what I'm talking about).  Granted, in the video, what's running is a program and not a dvd menu, but is something similar possible in encore?
    http://www.youtube.com/watch?v=JKMu-bybpI0
    I know I can make it so I go on a button, click enter, this brings me to a new menu with a new background, but I want to cut on the amount of menus.  I like the idea of the background changing automatically without having to go to a new menu.
    Thanks for your time and help!

    When using dupe Menus and Auto Activate, I strongly recommend that one sketch out the flowchart first, and also think about using Button and Menu names, that relate directly to where they need to Link. With a bunch of Buttons, it can get involved pretty quickly. With a bit of planning, things will be much easier. I usually will layout my flowchart in Adobe Illustrator, and use the images of my Menus, in that image. It really helps me plan things. However, using AI might be overkill for some Projects, and a pencil and paper would do the job.
    Good luck, and remember, if played on a computer, the effect will not be so fluid, as the user must click on the "original" Menu to get to the "dupe" Menu with the different background - just a limitation of Auto Activate on a computer. In a DVD player, it will be pretty seamless, and can look beautiful. I use this general technique to create what appear to be Sub-picture Highlights, that are really graphics.
    Hunt

  • Desktop background changes when I change the user

    The background changes from solid dark grey to solid dark aqua blue, when I make a quick user change. It happens automatically. Even when both desktops have the same (dark grey) background. This is a mess. Is it a bug?
    Thomas

    that usuall happens when you are not connected to the internet. if you were running wifi your connection could have been lost for a moment and then recovered.

  • Why does my launchpad background change automatically??

    i just fingered my launchpad background chagnes automatically. and also i found out that people say if u wanna change your background of laucnpad, you can just press option+command+control+b, i tried it several times and it works. but when the launchpad background changes itself, i cannot change it back!!i pressed those keys and they did not work....why??

    I am a new to macs and I am having the same problem. After downloading gogle chrome then installed I decided I did not want to use it. My mistake I decided to uninstall but simply dragged tha app from the finder widow to the trash. After that launch pad started to do the same as above.
    Plaese can anyone help?

  • Every time I turn my mac off, the desktop background changes. It always returns to the same picture, which was the second or third thing I changed my desktop to after getting my mac.

    Every time I turn my mac off, the desktop background changes. It always returns to the same picture, which was the second or third thing I changed my desktop to after getting my mac. I have background switching unchecked in my preferences, and I have never selected it as an option. Also, when I go to my preferences, it will show the icon of the picture I changed it to, even though the desktop itself has switched back.

    I would start with some basic troubleshooting.
    REPAIRING DISK PERMISSIONS -
    NOTE: refer to article "About Disk Utility's Repair Disk Permissions feature" found here http://support.apple.com/kb/ht1452 - for the actual apple article on these step. ----
    - click finder in the bottom dock, and in the window that opens, select applications in the left column - scroll through until you see the 'Utilities' folder and double click to open it.  Then double click on 'Disk Utility'
    - When prompted to select a disk volume or image, select the 'Macintosh HD' in the left column
    - ensure the the "first aid" tab is highlighted blue in the middle of the screen
    - click the button at the bottom that says 'Repair Disk Permissions'
    - this process will take a few minutes to run.  It will indicate it's done, by scrolling to the bottom of the "details area" displaying 'Permissions repair complete'
    Dan Frankes has written an excellent article for Macworld on "Permissions" and the need to repair them - see - http://www.macworld.com/article/52220/2006/08/repairpermissions.html.    Another good web site is - http://www.thexlab.com/faqs/durepairfns.html.
    REPAIRING DISK - About OS X Recovery - http://support.apple.com/kb/HT4718.
    - restart your computer hold down command + R keys on the keyboard to boot you into Lion / Mountain Lion Recovery mode
    - select english as your main language then the continue arrow
    - select "Disk Utility" on the resulting screen then 'Disk Utility' ---
    - When prompted to select a disk volume or image, select the 'Macintosh HD' in the left column
    - ensure the the "first aid" tab is highlighted blue in the middle of the screen
    - click the button at the bottom that says 'REPAIR DISK' .......NOT "Repair disk permissions"
    - this process will take a few minutes to run.  It will indicate it's done, by scrolling to the bottom of the "details area" displaying "The Macintosh HD appears OK"
    If you get any other message OTHER than "The Macintosh HD appears OK", like "the Macintosh HD was repaired successfully" run the "Disk Repair" again, until it displays  "The Macintosh HD appears OK".
    Once done, restart the computer as normal

  • Background change

    Hello everybody!
    I've a problem with background and frame.
    If I would change the background of a frame at the same time
    that the main frame's background change...how I can do that?
    The background of the main frame change on mouse click on a
    link on a left frame. I would the background of left frame change
    at the same of the main frame one.
    I'm sorry for my english but I'm Italian. Thanks to all. Good
    night! Laura

    sniper8752 wrote:
    i went to my pictures, and selected an image, then Set as Home Screen Image.  i do not want that anymore.  how do i remove it?
    Put another picture that you DO like there... same process--select the image > Set as Wallpaper.
    Or use the default theme wallpaper on the same menu.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Cinnamon background changer will not load background images

    Hello,
    Since about yesterday (when I did a pacman -Syu), the cinnamon background changer refuses to load any images to change the background to. When I run cinnamon-settings from a terminal and select backgrounds, the following occurs:
    Loading Backgrounds module
    Failed to convert /usr/share/backgrounds/gnome/Blinds.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Bokeh_Tails.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Chmiri.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Dark_Ivy.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Fabric.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Flowerbed.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/FootFall.png: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Locked.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Mirror.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Road.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Sandstone.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Stones.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Terraform-green.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Waves.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/backgrounds/gnome/Whispy_Tails.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /usr/share/themes/Adwaita/backgrounds/morning.jpg: 'NoneType' object has no attribute 'mode'
    Failed to convert /home/evan/.cinnamon/backgrounds/hd-wallpapers.jpg: 'NoneType' object has no attribute 'mode'
    So I'm assuming it's somehow not properly loading the images. I can't add any images manually either, since once I do it gives this error for that image as well.
    I can provide a list of the packages updated. Cinnamon was not one of them and downgrading Cinnamon did not help.
    Thanks in advance!
    Last edited by Ekkoria (2014-07-05 18:59:30)

    Possibly a change in python2-pillow
    Possible fix in /usr/lib/cinnamon-settings/bin/imtools.py line 862
    Change from
    if source == mask:
    to
    if mask and source == mask:

  • TS3274 I was just moving some of my apps around and the background changed to an x-ray look  ,,,  I don't think  I touched anything ,,, How do I get it back to the original ????

    I was just moving some of my apps around and the background changed to an x-ray look ,,, I don’t think  I touched anything ,,, How do I get it back to the original ????

    Settings>General>Accessibility>Invert Color>Off

  • Flash CS5: Stage background changes to white upon export no matter what color I set it to?

    Hello,
    As the title speaks for itself, I've been running into this problem since yesterday and couldn't figure out what is wrong with flash. Normally, I like to work with black background, so my stage background is always set to black, However, when I exported to view my project, the background changes to white. I've tried to check the preferences, setups and nothing I found suspicious is causing this.
    I've tried to create a new AS 3.0 document, and still, it gives me a white background when I export to view regardless if I set the stage background to red or blue.
    I've tried restarting my computer, and yet nothing is fixing it.
    If anyone can help me figure out this problem, I'll gladly appreciate it! Thanks..

    Thanks for the wonderful quick fix simPod_, I've deleted my mm.cfg file, but somehow this isn't permanent. It should do for now except the hassle of deleting the file and restarting flash. If anyone else have a permanent solution to this, I'll gladly appreciate any responses. Thanks!

  • [svn:fx-trunk] 11448: Making a small ItemRenderer change so that we don' t dispatch an unused, contentBackgroundColorChanged event anymore when the itemIndex gets set.

    Revision: 11448
    Author:   [email protected]
    Date:     2009-11-04 17:06:22 -0800 (Wed, 04 Nov 2009)
    Log Message:
    Making a small ItemRenderer change so that we don't dispatch an unused, contentBackgroundColorChanged event anymore when the itemIndex gets set.
    QE notes: -
    Doc notes: -
    Bugs: -
    Reviewer: Deepa
    Tests run: checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/ItemRenderer .as

    Revision: 11448
    Author:   [email protected]
    Date:     2009-11-04 17:06:22 -0800 (Wed, 04 Nov 2009)
    Log Message:
    Making a small ItemRenderer change so that we don't dispatch an unused, contentBackgroundColorChanged event anymore when the itemIndex gets set.
    QE notes: -
    Doc notes: -
    Bugs: -
    Reviewer: Deepa
    Tests run: checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/ItemRenderer .as

  • Is there a setting to prevent modification date change after adding label or changing orientation?

    is there a setting to prevent modification date change after adding label or changing orientation? I don't want to change the modification date when I haven't edited the image, but only rotated the view or rated/labeled it. Is there a setting to change to not have this happen?

    You have modified it, but why worry?  The date shot does not change.

  • HELP! I'm pretty sure I have a virus. everytime I shut down my mac and open it the background changes. the only thing i've downloaded was a software upgrade. I just recently got this mac so have no idea how to fix it. Please somebody help me!!

    I have just recently got a Mac, didn't buy an anti virus or anything because the store man said it wasn't necessary.
    After two weeks of use this update software notification kept poping up, so I did and now everytime I turn my Mac on the background changes.
    I've heard that this is how the Mac viruses start, I'm very new to this please somebody tell me how to fix it!!

    There are no viruses for osx.
    You are still under warranty.  Call Apple Care. Make sure you get a case number as all repairs have an additional 90 days of warranty. 
    #1 - You have 14 days from the date of purchase to return your computer with no questions asked.
    #2 - You have 90 days of FREE phone tech support.
    #3 - You have the standard one year Apple warranty.
    #4 - If you've purchased an AppleCare Protection Plan, your warranty last for 3 years.   You can obtain AppleCare anytime up to the first year of the purchase of your computer.
    Take FULL advantage of your warranty.  Posting on a message board should be done as a last resort and if you are out of warranty or Apple Care has expired.

Maybe you are looking for