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();
}

Similar Messages

  • JButton - avoid color change when clicked

    Hello All,
    probably this is a simply question, but i didn't find the answer.
    I have some JButtons in my window. When they are clicked, they change
    their background color for a momement (normal behavior). This is what I
    want to avoid. How could I do this?
    Thank you in advance.
    Ralf

    i haven't got the soources at the moment, but check it out from there... it's probably defined in some L&F class, like ButtonUI or something... you'd probably need to create custom *UI class.
    if you extend BasicButtonUI and override protected void paintButtonPressed(), then you may have it do as little as you please.
    easyest way would probably be copying original one, and then have it paint background with original background color, or not to fill it at all..

  • Why does the background color change?

    Hello world...
    I have a problem: when I load an external .swf into my current stage, its background color becomes like the one of current stage. Why?
    Please, help me.
    Emiliano.

    It's because there actually is no background inside Flass. That colored area (stage) you place your items on is just there to help you see them.
    For your problem, just place a colored rectangle on the bottom most layer and you'll be good.

  • Why does my font color change when I add an image to InDesign?

    Hello, I am doing a page layout in InDesign and I am using a light blue font for my title but when I add an image from Photoshop, the font color turns dark blue. When I open the InDesign file in Adobe Acrobat, my title is still dark blue. It's only when I make a PDF of the file in Acrobat and open it in the Safari browser that the title goes back to its original light blue font. Is there something I can do to fix this? Thank you!

    Not a good idea. The flattened PSD has lost all its layers, adjustments, and effects. I hope you don’t need to edit it or change any layer’s visibility. Either that or you now have two files to keep track of and have neutered InDesign’s Edit Original feature. Better to take Peter’s advice and place the text above the image so it is not affected by transparency flattening. If you need the text below because you want the drop shadow to interact with the text, then use Overprint Preview (View menu) or Separations Preview (Window > Output) to get a more accurate view of the text colour.

  • Cell/Background color changes when copying to other Excel 2010 document

    When you copy and paste report cells (e.g. CO report outputted in Office integration, MS Excel) to a new Excel file, the background color changed dramatically (to bright red).
    SAP Theme:  SAP Signature Theme
    Excel 2010
    We tried paste option > match destination formatting but does not help.
    Anyone has similiar problems?  Appreciate any help.

    dear friend,
    you would do:
    1. search SAP Notes;
    2. check out the updates/patches for your MS Office;
    3. replicate it on another computer/another sap user (make sure it is a local issue)
    good luck!

  • Why does the frame color change to black when I copy and paste between documents?

    Copying and pasting between documents in Indesign. The color of the text stays the same but the lines and frames change from a specified color to black. Also changes when I drag and drop can anyone tell me how to fix this?

    You have not provided any exact information like what version of ID, system info, paragraph styles, color definitions and whatnot, so we can't know what is going on. either way, ask in the ID forum and provide all those important details.
    Mylenium

  • Numeric Control - Text and Background Color changes when operating inc/dec arrows

    Hi,
    I'm developing an application that has a panel with black background and green or red numbers. I've added numeric controls and configured the text color and text background color attributes accordinglingy. I set the numeric control to hot or validate  control mode and show the inc/dec arrows, since I want to be able to incr/decr the numbers.
    The problem is that when I run the application and I hit the inc/dec arrows, then the colors inside the numeric control frame become inverted: the black background becomes white and the green number becomes cyan. I've created a callback function assosicated with the numeric control and tried forcing the text and background color, in the EVENT_VAL_CHANGED section, using the SetCtrlAttrribute() function, but to no avail. Also added ProcessDrawEvents didn't help.
    When I mouse click again outside the numeric control, then it reverts back to its original colors (green text, black background).
    Any suggestions as to how I can fix this ?
    I want it to keep its original colors at all times, even when I'm clicking the incr/decr arrows...
    Kind regards,
    pgriep
    Solved!
    Go to Solution.

    Ok, now I see what's happening.
    The effect you are seeing is a resul of standard numeric control behaviour combined with the black bcakground: when you use arrows to increment/decrement a numeric control its value will be automatically highlighted; on the default background you'll see the white area and figures highlighted in black (white numbers on balck background). If you set the background to black the system will automatically change the colors used to highlight the text, and that's what you're seeing.
    By the way, this does not happens if you use up and down keys on the keyboard: text is not highlighted so colors are not changing.
    Additionally, this is not only valid for numerics: see the behaviour of the string controls on the bottom of your panel when you tab up to them. This effect does not happen on controls set as indicator like the big clock in the upper part of the panel.
    The only way I can see to overcome this behaviour is to hide control built-in arrows and create your own up and down buttons with which you can manipulate the numeric control. I am attaching a modified version of your project with buttons on the left numeric; sorry for the poor aesthetic:  I have used some arrow icons I had on my disk, you may want to create your own arrows with the colors and shape you prefer.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?
    Attachments:
    ModifiedApplication.zip ‏9 KB

  • Why does my font/text change when I switch from Classic 3D to Ray traced 3D in After Effects?

    My font/text changes when I switch from Classic 3D to Ray traced 3D. Why is it doing this? Also, I cant get the font/txt to look the same after I switch from Classic to Ray traced. How can I get it to look the same?

    I am pretty new to After Effects so I hope it's not my inexperience that's causing the problem. (It probably is)
    I just updated to the most current version of AE.
    I am on a mac pro late 2013 12GB 6 core. Running OSX 10.9.4
    Okay so after looking at it a little closer, I think the color is what mostly changes. The first screenshot is the what the text look like with Classic 3D and the second screenshot is what it looks like after I change it to Ray traced 3D. Also under the "Mode" section..the pull down that says "Normal" disappears. I'm wondering why the font color is changing?

  • SWF background color changes when uploaded to server

    I built my Flash all pretty, based upon a black background.
    When ran on the local copy, the black shows up as black & the
    Flash is like it should be. However, as soon as I upload it to the
    server and run it from there, the Flash background changes to
    white, which as you can imagine, royally screws up the visuals. Any
    clue as to why it would do this?! I can't think of any reason why
    it should. The server is in-house and will only be used for an
    Intranet page, so any possible corruption over the web should be
    negated. Help!!

    I'd like to post a link, but like I said, it's only internal.
    When I look at the HTML, it's set to black (background-color:
    #000000). Also, when I load it, the page itself is black, but the
    background of the Flash *only* has turned white. I can load the
    exact same page on my local drive and it comes up black. I've got
    publish settings to Flash 8 (my version) and AS 2.0. I checked that
    first because I've published lower in the past and had
    issues.

  • Background color changes when using AJAX

    I'm using NetBeans and the plugin Project Dynamic Faces Ajax Components. Each time a radio button is selected a few textfields are hidden/shown.
    But each time I press a radio button, my background color of my JSF page is changed (from blue) back to white.
    Does anyone know how to disable this, or just how I can set the background of the page manualy in the java code.
    I've tried this.setBackground(...); , but it doesn't work.

    Hi. I currently use Canon, and i only see it in my RAW files.  All camera firmware is up-to-date. I am running latest version of Aperture, but still running 10.6.8. I went through a bunch of old photos where there was a good red color of something and i was able to duplicate the problem each time. Where there was a large area of red, it was VERY noticable. Also, I used to shoot with Nikon and my NEF files do the same thing where there is a nice red.  It seems to be an Aperature "thing."
    What i find so curious, is that even if I make no adjustments to the Levels sliders, just checking the box alters the color, same with the Vignette brick.  Also, I do color calibrate my monitor. thanks.

  • Item Background Color changes when placed in production (Forms 10g)

    Hello All,
    I have searched the forum on this topic, but have not been successful in finding a topic/solution for multi-line items that need to render a different color than the rest.
    I have used set_item_instance_property (and set_item_property) as well as using a VA to resolve this issue to no avail.
    When I view the form in the browser - initially in query-mode, I see the color that I have set for the item. Once the query is fetched and I am in non-query mode (display), the items background color is replaced to the standard color (off yellow) for non-editable fields.
    I have taken all of the subclasses off, used the item property from the pallette as well as manually programmed within a trigger and cannot get this item to stay the color that I have set.
    Can anyone help me get this working?

    Are you using the 0 to 100 rgb color assignments you see in the Forms Builder color palette? If so, that is your problem. At run time, you have to convert the color numbers to 0 to 255 numbers. Just multiply each of the three parts by 2.55
    Or maybe there is come code running elsewhere in your form that is setting the color after your code is run.
    Search your form for background_color.

  • Why does the PDFs' name change when i view them in the iBooks app?

    i have some past papers and marking schemes in my iTunes library....when i sync them to my iPad, they appear just fine....they are there just the way i named them and all...
    but when i open them, the name changes to some coded-ish name with lots of numbers and all that....
    is it possible for me to change some setting and save the name i want for those PDFs? Or am I going to have to live with this madness?
    please help!

    Hello, I wanted to follow up on this issue after reviewing some of the changes with the current update. [https://bugzilla.mozilla.org/show_bug.cgi?id=1049521] This bug addressed some Windows HKEYs that are changed when Firefox is updated/or installed.
    As an update, a patch has been made and changes are on the way for fresh installs of Firefox :-)

  • Why does the background color in a saved pdf disappear when opened in Acrobat Pro 9.0 but appears when opened in Adobe Reader?

    Does someone know why this happens? BTW it only started recently.

    Hi bozieone,
    Does this issue occur on any test pdf created as well?
    What OS are you using?
    Regards,
    Rave

  • JButton background turns grey when clicked

    Hi,
    I have a JButton that I have customised by setting the background colour to beige and hiding the border using setBorderPainted(false). I have also got rid of the outline that normally appears when you click it using setFocusPainted(false).
    My problem is that when I run my applet in a browser and I click on a button, the background flashes grey while I'm clicking. This only happens in the browser - when I run it in JBuilder there is no problem. Can you help?
    Thanks!
    David

    Unfortunately, this is a consequence of having the UI logic separated from the button component. In order to change the button's selected/pressed color, you have three options:
    1) set the UI to your own custom UI (see http://java.sun.com/products/jfc/tsc/articles/sce/). You don't have to implement a whole new UI, but you'll still have work cut out for you if you're not familiar with this.
    2) change the color for ALL the buttons in the application usingUIManager.set("Button.select", new javax.swing.plaf.ColorUIResource(0,0,0)); Obviously, you should specify a good color.
    3) create a subclass of JButton, call setContentAreaFilled(false); on it, and paint it yourself.

  • Why does my block diagram change when I copy my code to another system?

    I am doing development work on a laptop on Win XP and using LabVIEW 2009 with service pack 1. When I copy the code to the target system, my block diagrams are changed and no longer fit the screen. Much of the code is spread out, mainly down. The target system is running Windows 7 and also has LabVIEW 2009, SP 1.
    I notice that any constants that are clusters are expanded when copying the code to the other system. I've gone in and turned off the autosizing for these clusters but they are still expanded. I like to shrink them to a small size for saving space.
    I've gone through and manually re-adjusted the block diagram on the target system, but when I copy it back to my development laptop, the same thing happens again. This is not an acceptable way to develop code and it has caused a real problem to proceed. I'm contracting this work and must develop this code offsite. Can anyone please help me with this? I can't keep restructuring my block diagrams every time I copy the code from one system to the other.

    Windows XP used Tahoma size 8 as its basic system font.  When MS came up with Vista, they changed it to Segoe size 9.  I'm not sure what Win 7 is, but I think it is the same as Vista.  That font change, and certainly font size change seems to be the underlying cause for block diagrams changing their appearance.  (And for front panel controls and labels as well.)
    LV seems to use the Windows system font as its default font.  Interestingly, it seems like the font sizes in LV are something like size 12, 13, 14, 15.  I think a size 9 is equivalent to a size 15, but I'm not sure about the comparisons.  (Check out this thread.)
    There are a few things you can do to try to make one system look more like the other.
    1.  Go into the Windows screen settings. In Vista, right click desktop, Personalize.  Window color and appearance.  Open classic appearance properties.  Try changing the color scheme from Windows Aero, to something like Windows Classic or Windows standard.  They both use Tahoma 8.
    2.  Or same as Step 1, but go further into Advanced button.  Pick on any option that uses font such as Menu, Message Box, Active or Inactive Title Bar and change the font there.  I'm not sure which of the items that has a font setting is the key one.
    3.  LV uses 3 fonts called Application, System, and Dialog.  I think each of those map to one of those Windows options, but I'm not sure which goes to which.
    4.  In LV, Tools/Options/Environment has a subsection called Fonts.   Those 3 basic LV fonts are selectable there.  There is also a checkbox for me which is checked and says to use default.  If you uncheck that checkbox, a Font Style button becomes enabled.  You go in there and you can choose fonts and sizes.  And the Application, System, and Dialog fonts as well as all the usual fonts names (Arial, MS Sans Serif, Greek, ....) are selectable along with fonts sizes.  Play around in there.  The whole section is very confusing, and I have no idea how it works.  I recommend going to this idea A better way to specify (default) fonts and putting in a vote.   Also this idea, Fix font behavior between windows versions, platforms & executables, deserves some love.
    5. Some of these settings can also show up in your LabVIEW.ini file.
    FPFont = "0" 15
    BDFont = "0" 13  (I think the "0" means app font, "1" means system font, and "2" means dialog font)
    Also,
    appFont="Tahoma" 13
    systemFont="Tahoma" 13
    dialogFont="Tahoma" 13
    (And if necessary, put these in your built application's .ini file)
    As you can see, there are a lot of different things going on and they also seem to conflict with each other.  I starting stumbling on the block diagram issue between working on my app on XP at work and on my Vista machine at home about 6 months ago.  I think my problem actually started with the front panel when I was trying to align labels, and use some arrow head decals on boolean buttons.  I think I did the customization of buttons in a couple different ways (because I did some, came back later to do others, and couldn't remember exactly how I did it.)  As a result some decals looked different than others when I changed machines.  And I swear going from XP to Vista, or Vista to XP the problem got both worse ways rather than let's say larger one way, and smaller the other way.
    Replying to your message is about as much to me trying to combine all the pieces of knowledge I've stumbled across over the past months and year as it is for trying to help you.  Hopefully, this information gives you some places you can look at and play with.  (I bet #1, would be a quick, easy way to solve your immediate problem, but I haven't really tried it myself to be sure.)
    I hope someone from NI who has a better understanding than me about these font issues could jump in and correct any mistakes I made, or add anything I might have left out.  What we really need is some sort of "nugget" or National Instruments white paper that really explains all of this in ways we can use rather than us stumbling around in the dark doing things trial and error to figure it out.  Generally, any changes to the .ini files require you to shutdown LV and restart it to take effect which can take a couple minutes.  And considering all the various combinations of things that can be done above, your talking about dozens of possible restarts, and sending .vi's between two different PC's with two different operating systems, before figuring these things out.

Maybe you are looking for

  • SetInt cannot be used in Red Hat Linux.Why?

    setInt cannot be used in Red Hat Linux Please send me:[email protected] Thank you.

  • How do I save photos from messenger

    How can I save photos from messenger

  • Query regarding Crystal Reports Server

    Hi, I am new to Crystal Reports. I have created a couple of .rpt files using CR2008 and I am loading these report files in my aspx pages using CrystalReportViewer control. I am planning to host my webApp on IIS in production environment. Maximum simu

  • Roaming between APs causes reauthenticaion w/ CCKM

    I have a small set up with a 2106 controller and two 1252AG access points. Each AP is on a side of a floor less than 100' from each other. But with columns and partitions in the way they just barely overlap one another. I have 2 WLANs configured with

  • Telnet/SSH as root not working

    I have freshly installed Solaris10 U5 through network installation method. After installation is over, i am not able to login as "root" over the network through Telnet/SSH What file we need to edit to disable this rule ?