JButton Background Color difference Windows/Solaris

I have a GUI application that has several JButtons, and the program sets them to different colors based on data received from a network. The program was developed on Solaris, and the GUI has several users. We used setBackground(Color.XXX) to set the Colors. We have users that use the GUI on windows. On Solaris, the entire JButton becomes the desired color. On Windows, the JButton is gray, and only the outline of the button is in the desired color. Is there anyway to configure the Runtime Environment on Windows so that the entire button is the desired color. If not, what other options are there?
Thank You in Advance for Your Help!!!

I followed these threads and none of these solutions created the LAF I am after. What I ended up doing is creating my own "button" by extending JPanel. This has a consistent look across all LAF's & OS's I've tried it on. I just override mouseClicked to get the button specific behaviour that I need.
private class MyButton extends JPanel implements MouseListener
public MyButton(Color color)
setBorder(BorderFactory.createRaisedBevelBorder());
setBackground(color);
addMouseListener(this);
public void mouseClicked(MouseEvent e)
public void mousePressed(MouseEvent e)
setBorder(BorderFactory.createLoweredBevelBorder());
public void mouseReleased(MouseEvent e)
setBorder(BorderFactory.createRaisedBevelBorder());
public void mouseEntered(MouseEvent e)
public void mouseExited(MouseEvent e)
}

Similar Messages

  • Cannot change JToggleButton background color when Windows XP theme is used

    I wanted to change the background of a JToggleButton when it's pressed. I tried a few things, such as
    UIManager.put("ToggleButton.select", Color.RED);
    setting button's background, button's UI.
    but nothing worked.
    so I tried changing desktop theme from Windows XP to Windows Classic, then i was able to set button's background.
    The following is a simple test program, by switching theme, the toggleButton looks differently.
    Does anyone know how I can change JToggle button's background color under Windows XP theme?
    Thank you in advance!
    import javax.swing.*;
    import java.awt.*;
    public class ToggleTest {
        public static void createGUI(){
            JToggleButton button = new JToggleButton("Test");
            button.setBackground(Color.BLUE);
            JFrame testFrame = new JFrame("Test Frame");
            testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            testFrame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
            testFrame.getContentPane().add(button);
            testFrame.pack();
            testFrame.setVisible(true);
        public static void main(String[] args){
            try{
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                //UIManager.put("ToggleButton.select", Color.RED);
            catch(Exception ex){
                ex.printStackTrace();
            SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                    createGUI();
    }

    class myToggleBtn extends JToggleButton {
      String s;
      public myToggleBtn(String str, Boolean sel) {
        super(str, sel);
        s = str;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (this.isSelected()) {
             int w = getWidth();
             int h = getHeight();
             g.setColor(Color.green); //selected color
             g.fillRect(0, 0, w, h);
             g.setColor(Color.darkGray); //selected foreground color
             g.drawString(s, (w - g.getFontMetrics().stringWidth(s))/2 + 1, (h + g.getFontMetrics().getAscent())/2 - 1);
    }

  • Why does JButton background color change when  clicking ?

    Hello,
    I have defined :
    JButton mybutton = new JButton(Icon xxx) ;
    with no associated text and I set both foreground and background colors to black, and an empty border.
    This is because the background color of the container which contents this button is also black and I want to see only the button icon.
    When I click on the icon , the button background color becomes grey. How can I change this to make it remains black ?
    Thanks a lot.
    Gege

    Well, the color changes because that is how the look and feel is defined,
    presumably to give better feedback to the user that she has clicked the
    button.
    If you don't want this, you could try using a different L&F which doesn't do this.
    Alternatively, If you've only got the one button, you could just do
        UIManager.put( "Button.select", Color.BLACK );If you have multiple buttons, and you want the other buttons to behave
    normally, you can extend the one button and have it change the color
    while it is pressed, e.g.,
    import java.awt.*;
    import java.io.IOException;
    import java.net.URL;
    import javax.swing.*;
    public class ButtonSelect extends JFrame {
         public ButtonSelect() throws IOException {
              super();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel panel = new JPanel();
              panel.add( new JButton( "Normal" ) );
              Image img = Toolkit.getDefaultToolkit().getImage( new URL("http://www.google.com/intl/en/images/logo.gif" ) );
              ImageIcon ii = new ImageIcon( img );
              JButton b = new JButton( ii ) {
                   static final private String KEY = "Button.select";
                   public void paint( Graphics g ) {
                        Color save = null;
                        if ( getModel().isArmed() && getModel().isPressed() ) {
                             save = UIManager.getColor( KEY );
                             UIManager.put( KEY, Color.WHITE );
                        super.paint( g );
                        if ( save != null )
                             UIManager.put( KEY, save );
              b.setForeground( Color.WHITE );
              b.setBackground( Color.WHITE );
              b.setFocusPainted( false );
              panel.add( b );
              getContentPane().add( panel );
              pack();
              setVisible( true );
         public static void main( String[] a ) throws IOException {
              new ButtonSelect();
    }

  • JButton background color question

    Hi everybody,
    I have a feeling I'm going to get slammed for this, but I have to ask a very general question and hope for an answer.
    I have a JDialog on which buttons don't seem to hold their background color. That is, when I use setBackground, the only color change I get is a very thin outline of the color, and the rest of the button is white. The strange thing about the button is that the white center actually seems transparent--if I change the panel the button is on to another color besides white, the center of the button turns that color.
    I've tried to solve this problem with setOpaque( true ), setContentAreaFilled( true ), setBackground( color ), setForeground( color ), and I'm pretty sure every combination of those.
    Unfortunately, I haven't been able to reproduce this in a test case, so I can't give a SSCCE, although I've tried for a while now to make one.
    So...has anyone ever run into a problem like this and can give me some advice? I'm sorry I can't be more specific, if anyone has a question I'll do my best to answer.
    Thanks,
    Jezzica85

    I have a feeling I'm going to get slammed for this, but I have to ask a very general question and hope for an answer.Why would people be harsh on you? The only risk you take is: vague question => vague answer (or random).
    So...has anyone ever run into a problem like this and can give me some advice? I'm sorry I can't be more specific, if anyone has a question I'll do my best to answer.Never seen that myself, so I'll add a few random questions/thoughts:
    I have a JDialog on which buttons don't seem to hold their background color. That is, when I use setBackground, the only color change I get is a very thin outline of the color, and the rest of the button is white.- are you using a custom JButton subclass? If yes are you certain the subclass does not override paintComponent()?
    - If not, the button is painted by its ButtonUI. Can you tell which UI class is used (sysout(+theButton.getUI()+)?
    The UI is set according to the LookAndFeel.
    - Do you set any special LookAndFeel (+UIManager.setLookAndFeel(...)+, or look and feel's UIDefault properties in your app (generally that is done at startup)?
    - If not, can you tell the current look and feel when you bring up the dialog (+UIManager.getLookAndFeel(...)+, although that can be inferred from the ButtonUI subclass' name.
    I've tried to solve this problem with setOpaque( true ), setContentAreaFilled( true ), setBackground( color ), setForeground( color ), and I'm pretty sure every combination of those.FYI, the ButtonUI paints the button however it sees fit; in particular it doesn't have to respect the colors, opacity, filling... properties.
    Eventually:
    - are you using a custom JDialog subclass (probably, as that's generally how people write dialogs; not the best way IMHO, but there are cases where this is hard to avoid).
    I see you can't provide an SSCCE right ow, but maybe you can try to narrow the list of suspects in your side?
    - Do you reproduce the same problem at startup, if you bring the JDialog up as soon as possible?
    - Do you reproduce the problem with a mere JOPtionpane.showMessageDialog(..., theButton,...)?
    - Do you reproduce the problem outside of the JDialog context (I see you mention using a different JPanel, but is that in the dialog or somewhere else?
    Good luck with your investigations.
    Edited by: jduprez on Sep 30, 2009 8:20 AM

  • JButton background color on XP difference with theme classic and XP

    Hi all,
    I got a problem on Windows XP JSE 1.5.0_01 when trying to set the
    background of a JButton (or to be more precise of a subclass of
    JButton, but no override of paint or paint Component).
    The button background behaviour is correct with the theme Windows
    classic but not with XP Windows one. In the later case, only the
    background below the button is coloured, the rest is grey: impossible
    to modify the colour of the button itself.
    Any idea?
    F.

    It did.
    Thanx a lot.
    F.
    Maybe this thread will help you:
    http://forum.java.sun.com/thread.jspa?forumID=57&threa
    dID=430926

  • Can i change the background color of a file from white?

    i want to change file backgrounds from bright white, to a more soothing color.

    Each program is different and do not always have controls to change the background colors.
    For jpg files view this:
    https://www.youtube.com/watch?v=u5-WmuLFHys
    or this for jpeg
    http://www.wikihow.com/Change-an-Image-Background-in-MS-Paint-(Green-Screen)
    or this for pdf
    http://sodapdf.com/blog/sodapdf-tutorials/how-to-edit-a-pdf-file/pages/how-to-add-or-replace-a-backg...
    or of a folder
    http://www.sevenforums.com/customization/336693-how-change-background-color-folders-windows-7-a.html
    Anything else, I can't help you.
    Please mark my post as SOLVED if it has resolved your problem. It helps others with similar situations.

  • Bridge CS4: Changing preview window's background color

    How can I change the preview window's background color? (default is black) It happens that I have some black images with alpha (transparent background)  and being all black they blend with the preview window's background color. can this be changed?? I looked everywhere and the only thing I found is how to change bridge's appearance, but not the preview window's bg color. Thanx in advance

    Try changing the thumbnail style to HQ or ?, and see if that makes any difference.  In Quick thumbs it may not display layers.

  • An applescript to change the background color for all finder windows

    I'll start off by telling you what I am trying to achieve, then show you what I've tried.
    I have a macbook with several HDD's attached. what I want is for each of those hdd to have a specific finder window background color. so no matter where I am in that hdd the background color will always be the same. so for instance if I set the background color of hdd 2 to blue then as long as I see a blue background I know that I'm within hdd 2.
    I've tried setting up an applescript to do this but can only get it to change the open finder window, and none of the subfolders have their backgrounds changed.
    here is what I have so far:
    tell application "Finder"
    tell the icon view options of the front Finder window
    set the background color to {52942, 54484, 31097}
    end tell
    end tell
    so how do I get this to apply to all subfolders without opening each one and running the script.
    thanks in advance for any and all help with this

    According to this article:
    http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as2039.html
    it seems that the various options can only be set while the window is open and in icon view.
    Rather than manually opening the window of every single folder on the hard drive, it should be possible to write a script to open every folder in sequence, make sure it is in icon view, change its background, then close its window. I have never been any good at the "actions within actions" procedure needed for folders within folders, so maybe someone else with the necessary knowledge and experience might be able to assist in this regard. Such a script would probably take a few minutes to complete while it ran through "every folder of every folder", but it sure would be quicker to have the process automated than to do it by hand - computers are really good at repetitive tasks (as long as the instructions are accurate, of course!).
    On the other hand, you might like to try the following:
    open a few windows in icon view, choose Show View Options in the View menu (I'm in System 10.4), click the radio button All Windows, click the Color radio button under Background, then choose your color. It might achieve what you are trying to do.

  • Problem in Setting Background Color for JButton

    Hi,
    I am using Background color for JButton (color is selected from the customized JColorChooser created by us) where it contains the option of transparency. If we choose light color, then the background is set to JButton, but when we mouse-over the JButton, other components inside the container (JPanel) is getting displayed inside the button.
    Can anyone help to sort out this problem.
    Thanks in advance.

    Hi,
    Here is the code.
    DialogWrapper is JDialog and ColorEditorPane is JPanel.
    DialogWrapper     dlg         = new DialogWrapper();
    ColorEditorPane colorPanel = new ColorEditorPane();
    colorPanel.setValue( _data.getTransparentColor());
    dlg.showWrappedDialog( colorPanel, "color_help", "color_dialog" );
    if( dlg.isOK())
    Color chosenColor = (Color) colorPanel.getValue().getContent();
    _data.setTransparentColor( chosenColor );
    _transparentColorDisplay.setBackground( chosenColor );
    _transparentColorDisplay.setOpaque( true );
    this.repaint();
    this.doLayout();
    this.validate();
    }I've several components like JCheckBox, JRadioButton, JTextField in "this".

  • How can i change the background color in the mobile windows adobe reader app? i want to change it from black to white but don't know how.

    really want to change the background color of my documents in the mobile app. ive tried to search the answer online, in blogs and other various 'life hacks' blogs or articles, but so far everyone is talking about the desktop version. i really want to figure this out. is there even an option for the mobile version for windows? the only editing icons when a document is open are: export, home, make public, search in document, highlight/strikethrough/underline/comment and continuous/single view. if there isnt an option to edit background color, can i suggest that the makers of the windows mobile version make one, and make it fast please! any help would be appreciated. -CHANGE BACKGROUND COLOR

    hi, thanks for helping me ...
    i have used the above url and made changes to my OAF page, but i didn't get the desired output and its also giving as the above code output .
    i kept OraBgGrayVeryDark in Css style in property inspector for every region including PageLayout and i also did some changes in cabo/styles/*.css classes.
    eventhough it is picking the color upto footer level only and it is not applying for advanced table also.
    can anyone please give your views in this..

  • How to change background color in a window? Please help.

    Please help me to set background color to my window that includes some panels components.
    I have tried
    content.setBackground(Color.green); and
    frame.setBackground(Color.RED);
    but nothing works?
    Please what should I change in my code? Thanks already in advance for helping!!
    Main parts of my code:
    public void addComponentToPane(Container allComponents) throws IOException
    definePanels();
    allComponents.setLayout(new BoxLayout(allComponents, BoxLayout.Y_AXIS));
    allComponents.add(panel_introduction);
    allComponents.add(panel_n);
    allComponents.add(panel_resultTitle);
    allComponents.add(panel_w);
    allComponents.add(panel_testing);
    allComponents.setVisible(true);
    public static void main(String[] args) throws IOException
    try {
    GraphicsDevice device;
    Container content;
    JFrame frame = new JFrame("ImageOrder");
    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingApplication app = new SwingApplication();
    content = frame.getContentPane();
    content.setBackground(Color.green);
    app.addComponentToPane(content);
    frame.setVisible(true);
    finally {
    System.out.println("helle");
    }

    import java.awt.Color;
    import javax.swing.*;
    class Test extends JFrame {
         public Test( ){
              getContentPane().setBackground(Color.RED);
              pack();
              setSize(500, 500);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) {
              new Test().setVisible(true);
    }

  • How to change background color in AutoComplete window ?

    Is it possible to change background color in AutoComplete window ?

    Bob, A.Ankit, you're both chasing a ghost here.
    The screenshot shows an autocomplete enabled textbox with its dropdown list of autocomplete values to choose from. There is no property defining its backcolor. Not in the textbox nor in any class, neither any other baseclass nor _combobox of _base.vcx
    The only way to chnage that color is not recommended, via changing windows theme colors. That would effect any window and control.
    If you need another color even turning off themes won't help as VFP doesn't offer any property controlling that color, so you really would need to implement the autocomplete feature yourself, if you want the specify this backcolor.
    Bye, Olaf.
    Olaf Doschke - TMN Systemberatung GmbH http://www.tmn-systemberatung.de

  • Webcenter Spaces-Annoucements pop up window background color change

    Hi,
    I am using oracle webcenter 11g PS3.
    I am using ANNOUNCEMENT task flow in my webcenter spaces application, there i can make some UI based changes but i need to change the background color of POP UP window when i click on any announcement subject to view complete announcement and any way to customize some properties in announcements. please help. Thanks

    I am changing the lightblue  background (#F5F7F9) of the portal by downloading the theme
    and the unzip the portal.zip and then the default.properties:
    parPrtlBodyBackground=\#F5F7F9
    parDocumentBackgroundColor=\#F5F7F9
    Change the values to the required background color.
    Regards,
    Kai

  • Set property for  background color for JButton

    I am attempting to change the colors of the UI for JButton. The change does not appear to be taking. The reason appears to be that JButton, and for that matter JLabel setOpaque(false); How can I globally change this to setOpaque(true);
    Second is there a way to save the default property hash table after the changes are made so that it will run the next time the program is executed.

    Thank you for responding. I don't feel that I have been clear in the statement of the problem. I have written a medium size desktop application(20,000 statements). I am trying to customize the color scheme by modifying the default laf properties color entries. I can modify JPanel through a put to the properties hash table. When I attempt to change the background color for JLabel and JButton it doesn't seem to take. I believe that the reason it doesn't take is because opaque(false). Is there a property that allows the overide of opaque to true or do I have to change all of the numerous JButtons in my program.
    I have decided to store all changes in a file and make the changes at the point that the program initializes each time its run.
    I am not looking for specific code but an approach.
    I would appreciate your advice.

  • Background Color to a Window

    A right click on a window such as, say, Documents or any subwindow within that window such as Pictures will reveal a menu that includes "Show View Options". Among other things the view options allow one to change the background appearance. One may choose from white, color or picture. I like to select "color" and choose from the palette a very light gray and then click "OK" This cuts down on the glare of a pure white background. The problem is that the color selection does not hold. The next time I return to that window the background is of another color, sometimes so dark as to be near black. I can reset the color back to the light gray, and as often as not the next time I open that window the color is back to a much darker color again. Help would be appreciated.

    OK, a further look seems to indicate that the unwanted background color change occurs only in a window containing thumbnail picture images (is that redundant?) For instance in Documents - Pictures - and then,say, Church Renovation, the background color in the Church Renovation window is not stable. It's different every time I open that window. Still need help.

Maybe you are looking for

  • Availability check

    Dear All We have a requirement that if a material say stock is 10 in unrestricted then we create a STO for 10 units then in MMBE  say in a plant 1000 still unrestricted will be 10 but in that details there will be 10 units STCK TRPSTORDER REL (under

  • Converting Filename Encoding

    Hello, I am trying to extract a .zip archive that contains CJK characters in its filenames. It was most likely created on a Windows machine. I tried the unzip utility and it produced invalid symbols. The same with 7za, but with slightly different one

  • Need to create stock item reservation with account assignment

    Hi Gurus, we are working on EBP 4.0 , extended classic scenario . We have a scenario where we want to create a shopping cart for stock item reservation with account assignment as work order. but when we try to do it , we are getting following error m

  • Screen looks normanl; Printing gibberish

    When I print messages from Earthlink.webmail they come out partially garbled in Firefox (not a problem if I use Internet Explorer. I don't think it's the printer, because it doesn't matter if I send it to a different printer.

  • Problems with Server

    My mail won't let me send messages, it says that sender address is rejected by the server, and it wont let me ping my outgoing mail server, (smtp.sbcglobal.net) i believe it may be a firewall problem, i'm trying on port 25 is there another port or a