Making buttons change colour when clicked on, sounds simple......

hello could somebody please give me the code to make a jbutton change colour when it is clicked on, muuuuuuuuuch appreciated, thanks!!!!!!!!!!!!!!!!!!!!

w e l l - k e w l !
I made a few adjustments here. Mainly for myself:- you know when you JUST CANNOT FIND THAT DARN COLOUR !!! - 'Pandavas' sexy little program is right on the button!
Click on the button and it cycles through colours randomly and tells you the RGB value ...import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ColorChanges extends JFrame implements ActionListener {  
  int red = 0;
  int blue = 0;
  int green = 0;
  java.util.Random rand = new java.util.Random();
  JButton button = new JButton("Colour Me!");
  JLabel label1 = new JLabel("                  The new colours are:                ");
  JLabel label2 = new JLabel("");
  public ColorChanges() {
    super("RGB VALUES:");
    setSize(200,108);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
    button.addActionListener(this);
    getContentPane().setLayout(new FlowLayout() );
    getContentPane().add(button);
    getContentPane().add(label1);
    getContentPane().add(label2);
    setVisible(true);  
  public void actionPerformed(ActionEvent eve) {    
        red = (Math.abs((rand.nextInt())%255));
        blue = (Math.abs((rand.nextInt())%255));
        green = (Math.abs((rand.nextInt())%255));
        cooller();
  public void cooller() {   
      button.setBackground(new Color(red,green,blue));
      label2.setText("RED: "+red+" GREEN: "+green+" BLUE: "+blue);      
  public static void main(String[] args) {
      new ColorChanges();  
}

Similar Messages

  • Links working but changing colour when clicked

    Hi
    All my links in my sidebar are working fine i.e. they open the correct page. However, I want the background colour on hovering to be #999 and the links to be #009 when the page opens. The former is fine but when the page opens in any browser the links show up in a different colour even though they are the correct colour when viewed in Design or Live View.
    The css rule is set to background colour #999 and colour #009 but I can´t figure out where the other colour is coming from. Also, when I click on the links in the live browser on some pages they change and stay changed to the #009 colour even when I change page.
    You´ll see what I mean here www.theonlineenglishclass.com
    Thanks

    Sorry to keep on but I keep going back to your page and looking:
    Add this:
    color:#000099;
    to the rule I mentioned in the previous post.
    Your links will then apply the color you want to the text but I think it will then apply to the link in each state.
    Martin

  • Links change size when clicked

    I have a site done in Dreamweaver CS5 that the links in the navbar change size when clicked.  The bar is set to 95% but the links look like they are abound 50% when the mouse button is pressed.  All references to the size of the links in the HTML and CSS Page Properties are set to 95%. None of the other links properties; a, a:visited, a:hover, a:active, a:link, a:focus change the size.
    I've looked for several hours for solutions.  Anybody got any ideas?  BTW, this is my first site in Dreamweaver.

    I don't see any change in font-size in Firefox 3.6 on Win.  But your code is a bit confusing.
    Change this:
    a {
        font-size: 95%;
    a {
        font-size: 95%;
    a:visited {
        text-decoration: none;
        color: #960;
    a:hover {
        color: #2A3FFF;
        text-decoration: none;
    a:link {
        text-decoration: none;
        color: #626262;
    a:active {
        text-decoration: none;
        color: #626262;
        font-size: 95%;
    To this:
    a {font-size: 95%; text-decoration: none}
    a:link {color: #626262;}
    a:visited {color: #960;}
    a:hover {color: #2A3FFF;}
    a:active, a:focus {color: #626262;}
    The order in which link styles are defined matters in some browsers.  LiVHA is an easy memory device for link, visited, hover, active.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Share button on Toolbar when clicked takes time to load ? Do you get that ?

    Share button on Toolbar when clicked takes time to load ? Do you get that ?

    After activating your iPad, go to the App Store and search for your free apps:
    1. Pages
    2. Numbers
    3. Keynote
    4. iPhoto
    5. iMovie
    6. GarageBand
    If apps are still showing the price: sign out>reboot>and sign in again
    Settings>iTunes and App Store>Apple ID

  • In my 4s display option doesn't come to change colours when I go to Setting-General. I am bored with blue colour. Please advise.

    In my 4s display option doesn't come to change colours when I go to Setting-General. I am bored with blue colour. Please advise.

    Go to Settings > Wallpapers & Brightness.

  • Trigger change badi when click a custom button

    hello guys i want to trigger the change badi when a user clicks on a button.  Any help would be create?
    I am using the set change by client setting it to true and then firing the refresh but it is not working?  Any clues?  Thank you.

    As I told you in that linked thread, I'd suggest trying to use SET_CHANGED_BY_CLIENT method on the context of your webdynpro. This is sufficient to make the system aware of a change and trigger the CHANGE badi.
    As far as I've observed doing my tests, the CHANGE badi is then triggered after an event that will follow the SET_CHANGED_BY_CLIENT execution.
    So I'd suggest two test:
    - pre-exit of the method you trigger when the user press your custom buttom: set_changed_by_client and then execute your code. See if the badi is then triggered;
    - if not: you could "force" a subsequent action after the button press, for example, a simple REFRESH of the view. Then I'm sure that, after the set_changed_by_client method, the badi will surely be triggered.
    Please be aware that I'm absolutely NOT a guru on these arguments, so I'm trying to give you some workarounds I implemented on an SRM 7 system. Probably some guru will have better and cleaner solution for your task, but as far as I've seen, these ones should meet your needs.

  • How do I stop text from changing colour when hovering over it?

    Hello, I have downloaded a template for Dream Weaver CS6 (Which is the version i am usig). When you hover over one of the boxes the top text changes colour to black instead of staying white... does any one know how i can make it so the text stays the same colour. I will post a print screen of it.
    Before clicking:
    View image: 1
    When hovering over it:
    http://postimg.org/image/wdsii9mab/
    I will post the code of the index page aswell: <!DOCTYPE html> <html lang="en"> <head> <title>Home</title> <meta ch - Pastebin.com
    Any help is appreciated. Thanks.

    Your unwanted pink hover color comes from style.css line 181 here
    .btn_{
        background: none repeat scroll 0 0 #cf3046;    border: medium none;
        border-radius: 3px;
        box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2);
        color: #ffffff;
        font-family: "Open Sans",sans-serif;
        font-size: 12px;
        font-weight: bold;
        line-height: 15px;
        margin-top: 20px;
        padding: 7px 13px 8px;
        text-decoration: none;
        text-shadow: none;
        text-transform: uppercase;

  • How To Make Shapes Change Colors When Clicking on them. Example Sheet Sales Data.xlsx template with Excel 2013

    My question is related to the Sales Data.xlsx template that comes with Excel 2013
    IN this workbook is a sheet named Sales Data. It has, 3 shapes. One each for each of the tab sheets in the workbook. When I click on the 'Sales Report' shape it selects the sales report tab. When you do this the shape changes color and the 'Sales Data' shape
    also changes color.
    However I'm unable to figure out how the colors are changing. 
    I don't see any macros in the workbook/worksheet. Nor do I see any code for worksheet events. I don't see any modules in VBA either. I think what is happening is that there are 2 shapes. When you click on one, the one shape goes to the background and the
    other one comes to the foreground.
    I'm no sure how it's doing that. 
    Can someone look at this template, Sales Data.xlsx that comes with Excel and explain how this functionality works?
    Thank You
    Keith Aul
    Keith Aul

    The shapes are exactly as I suspected, each of 3 sheets has 3 'navigation' shapes. The shape with the same name as the sheet has no hyperlink and is coloured differently to indicate it refers to the active sheet. The other two have hyperlinks linked to respective
    sheets. 3x3 shapes, 9 in total, none of them ever change colour!
    It's logical though not necessary to name each shape same as the sheet it links to, but they'd work just as well with their original default names.
    For aesthetics, the shapes that refer to own sheet have a horizontal line on top, actually two shapes as a group.
    If still confused copy each set of 3 shapes to a 4th sheet, or open two new windows so you can see all three sheets at the same time.

  • SUBMIT button works only when clicked twice... Online interactive form

    Hi,
    I have created a interactive form with SubmitToSAP button. In this I will enter a contract number and will click SUBMIT button.
    For the first time it is fetching the contract details properly.
    In the same form, i am changing  the previously entered value with another contract number and clicking SUBMIT.
    Now the details for the previously entered contract number is only displayed. Again if i try for the same value ( which i used for the second time )  and press submit, it is workin correctly.
    So, the problem is, except for the very first time SUBMIT button action, the button works fine only when clicked twice..
    please help me in solving this issue..
    Regards,
    Surya.

    Hi,
        In addition to my previous post, I am also using RESET FORM button from Library.
    First I am entering the contract number (say 400000000) in the form and clicking submit button. The contract details are fetched and displayed in the form.
    Now i am Resetting the form using Reset Button, and giving new contract number (say 400000020).  When  I pressed Submit button , the details of the first entered contract number (400000000)  is coming.
    Then again I am giving 400000020 or any other number, it is fetching the details correctly for that number...
    Can anyone help me in this issue..
    Thanks,
    Surya.

  • Cs4 problem with link text changing size when clicked

    designing in cs4, the actual text of my text links become huge for a split second when clicked, and then they go back to normal size.  I don't know what is causing this.  I don't want them to change when clicked.  Any ideas?  thanks in advance.

    John,
    If you need all the CSS code, I will attach it below:
    @charset "utf-8";
    body  {
        text-align: left; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
        color: #000000;
        background-color: #333;
        padding-top: 0;
        padding-right: 0;
        padding-bottom: 0;
        padding-left: 0;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 14pt;
    .twoColFixLtHdr #container {
        width: 950px; /* the auto margins (in conjunction with a width) center the page */
        border: 1px solid #000000;
        text-align: left; /* this overrides the text-align: center on the body element. */
        background-color: #E0D2A3;
        margin-top: 0;
        margin-right: auto;
        margin-bottom: 0;
        margin-left: auto;
        padding-top: 0px;
        height: auto;
    .twoColFixLtHdr #header {
        padding: 0px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
        background-color: #000;
        border: 5px ridge #333;
        margin: 10px;
        background-image: url(../website%20stuff/stepping%20on%20constitution--crop%20text.jpg);
        text-align: left;
    .twoColFixLtHdr #header h1 {
        margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
        padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
        font-size: 18pt;
        color: #FFF;
    .twoColFixLtHdr #sidebar1 {
        float: left; /* since this element is floated, a width must be given */
        width: 200px; /* the background color will be displayed for the length of the content in the column, but no further */
        padding: 10px;
        background-color: #E0D2A3;
        margin-left: 20px;
        text-decoration: none;
        color: #000;
        font-style: normal;
        font-size: 16px;
    .twoColFixLtHdr #mainContent {
        margin-right: 0;
        margin-bottom: 0;
        margin-left: 250px;
        padding-top: 0;
        padding-right: 20px;
        padding-bottom: 0;
        padding-left: 20px;
        text-align: left;
        font-size: 14px;
    .twoColFixLtHdr #footer {
        padding: 0 10px 0 20px;
        text-decoration: none;
        background-color: #E0D2A3;
    .twoColFixLtHdr #footer p {
        margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
        padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
    .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
        margin-left: 8px;
    .clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
        clear:both;
        height:auto;
        font-size: 16px;
        line-height: normal;
        text-decoration: none;
        font-style: normal;
        text-align: center;
        color: #00F;
    .mainarea {
        background-color: #FFF;
        border: 5px ridge #333;
        font-size: 14pt;
    .twoColFixLtHdr #container #footer {
        font-size: 14px;
        color: #000;
    .twoColFixLtHdr #container #header table {
        text-align: center;
    .twoColFixLtHdr #container #footer .clearfloat table {
        font-size: 14px;
        font-weight: bold;
        color: #F00;
    .twoColFixLtHdr #container #footer .clearfloat {
    .twoColFixLtHdr #container #header table tr td {
        font-size: 24pt;
        font-style: normal;
        font-variant: normal;
        font-weight: bolder;
        color: #000;
        background-image: url(Images/stepping%20on%20constitution--crop%20text.jpg);
    no link underline {
        text-decoration: none;
    .twoColFixLtHdr #container p {
        font-size: 14px;
        font-style: normal;
        color: #000;
    small text {
        font-size: 10px;
    .twoColFixLtHdr #container #header table {
        font-size: 16pt;
    .twoColFixLtHdr #container #header table {
        font-size: 16pt;
    .twoColFixLtHdr #container #header table tr td h2 {
        font-size: 22pt;
        color: #000;
    .twoColFixLtHdr #container #mainContent .twoColFixLtHdr {
        text-align: left;
        font-size: 14px;
    .twoColFixLtHdr #container #mainContent .twoColFixLtHdr h2 {
        color: #009;
        font-style: normal;
        text-align: left;
    .twoColFixLtHdr #container #mainContent .mainarea table tr td strong {
        font-style: normal;
    .twoColFixLtHdr #container #mainContent .mainarea table tr td p {
        font-style: normal;
        font-weight: normal;
    .twoColFixLtHdr #container #sidebar1 {
        color: #00F;
    .twoColFixLtHdr #container #mainContent .twoColFixLtHdr h2 em {
        text-align: center;
    .italics {
        font-style: italic;
    .italics {
    .font-color {
        color: #003;
    .italics {
        font-style: italic;
    .twoColFixLtHdr #container #mainContent .mainarea table tr .twoColFixLtHdr .blue a {
        color: #009;
    .twoColFixLtHdr #container #mainContent .mainarea table tr td .link-font-color {
        color: #00C;
    .align-center {
        text-align: center;
    .twoColFixLtHdr #container #mainContent .mainarea table tr .align-center {
        text-align: center;
    .center-align {
        text-align: center;
    Thanks,
    Craig

  • Why do windows change size when clicked?

    I have created a PDF file with links and some windows change size when I click the link.

    What is the version of PDF viewer application, if you this is the issue with few links, please try to manually edit them. Here the link to refer : http://help.adobe.com/en_US/acrobat/pro/using/WS58a04a822e3e50102bd615109794195ff-7cb3.w.h tml
    It would also be interesting to have a look at your file.
    Regards,
    Deepak

  • Button changes style when connected to Application Manager

    I've connected the standard axButtons to the application manager in a custom OI built in CSharp using Visual Studio 2008.  When I run the OI, the buttons change from the standard style (rounded edges, etc.) to what looks like a classic style (squared edges, no color gradient, etc.).  At first I thought this might be a limitation of CSharp, but when I ran the executable CSharp UI (shipped with Teststand), the buttons look correct.  Is there a reference that I've not added or something?  I've followed (pretty much copied) the code found in the full-featured CSharp UI, leaving out functions that I didn't need.
    Below is the only real code involving the two buttons.  It's pretty simple so I imagined it's a project property that I've setup incorrectly.  I've also included the namespaces I included.
    Thanks for any help
    using NationalInstruments.TestStand.Interop.API;using NationalInstruments.TestStand.Interop.UI;using NationalInstruments.TestStand.Interop.UI.Support;using NationalInstruments.TestStand.Utility; 
    // Connect Sequence Controls this.axSequenceFileViewMgr1.ConnectCommand(this.axEntryPoint1Button, CommandKinds.CommandKind_ExecutionEntryPoints_Set, 0, CommandConnectionOptions.CommandConnection_NoOptions); this.axSequenceFileViewMgr1.ConnectCommand(this.axEntryPoint2Button, CommandKinds.CommandKind_ExecutionEntryPoints_Set, 1, CommandConnectionOptions.CommandConnection_NoOptions); 
    Solved!
    Go to Solution.

    Scott, once again, thanks for your help.  I've tried several things relating to this manifest file, all to no avail.  First, I tried pasting the lines you mention into the <program>.vshost.exe.manifest file (the vshost file was the only manifest file that I could find, is this the correct one?)--no change.  In the "Application" tab on the project properties, I can select create w/o manifest or embed manifest.  I tried both, but from this point the original manifest file was deleted during the build process and did not show up anymore.
    The project includes the windows common buttons as well as the teststand .NET controls.  I assume this would accomplish the lines you mentioned, but I am a .NET newbie so I could be wrong there.
    I've attached a 2008 C# Express project which includes no code, only a windows common button and a teststand button on a form. When I run this program, I see the same behavior.  Can you take a look at this, and let me know if you see the same behavior?
    Thanks,
    Shawn
    Attachments:
    TS_Control_Test.zip ‏62 KB

  • Why does the browser window change colour when I bookmark a page or click the Downloads button?

    Using Firefox 20 on MacOS - when I click the Downloads button or Cmd-D to bookmark a page, the browser window changes from looking like this:
    https://dl.dropboxusercontent.com/u/35912963/01-firefox-before.png
    to looking like this:
    https://dl.dropboxusercontent.com/u/35912963/02-firefox-after.png
    Any thoughts would be welcome.
    Dan

    Hi there,
    Wow, that looks odd! I have no idea why that would happen, but I wonder if it's related to one of the add-ons you have installed? I see a red icon in the status bar that I'm not familiar with, which leads me to believe that you may have other add-ons installed. One thing to try is to start Firefox Firefox with add-ons disabled (you can do this from the Help menu). If you don't see this problem in that mode, the issue is caused by one of the add-ons. From the Tools menu, you can access the add-ons and disable them one by one. Remember to restart each time and then test it out.
    If none of that takes care of this, my other suggestion would be Firefox Reset: [[Reset Firefox – easily fix most problems]]
    Hope any of this helps.
    Cheers,
    David

  • How do I stop NEF images changing colour when I click on them in adobe bridge

    Windows 7
    Photoshop CS3
    Nikon DX40
    Photos shot as NEF files
    I am experiencing a problem when I look at my NEF images in Adobe Bridge. When I load them in and look at the thumb nails without clicking on them or opening them, the images look fine. As soon as I click on the images (just to select it not to actually open it) the colours change quite dramatically and i can't get back to the original images. It looks as if a greenish tone is put onto them and some of the detail is lost.
    I have tried the obvious things like resetting to default settings etc. Does anyone have any suggestions? thanks

    function(){return A.apply(null,[this].concat($A(arguments)))}
    I am experiencing a problem when I look at my NEF images in Adobe Bridge. When I load them in and look at the thumb nails without clicking on them or opening them, the images look fine. As soon as I click on the images (just to select it not to actually open it) the colours change quite dramatically and i can't get back to the original images. It looks as if a greenish tone is put onto them and some of the detail is lost.
    Can you upload such a NEF? Use yousendit.com if you don't have web space (and post the URL for downloading here).
    Gabor

  • Dynamic button change color on click and reset the unclicked buttons

    Hi,
    I have have 3 buttons created dynamically from JSON file.
    When I click on any of them the color is changed to red. (this is good).
    But when I am going to click another button the previous red that I have clicked earlier doesn't change to it's grey statement, except from the last button which is the only one that works (is changing between red and grey).
    If for the JSON make variable for the index e.g.(0,1,2) is working, but I want to make it work without index it. I want to make it with symbol's attr.
    here is the files if someone can give it a try.
    Dropbox - hover.rar

    At stageCreationComplete I have it as a function, but it doesn't work correct.
    I want to know why.
    The problem is that when I use getJSON, it creates the ChildSymbols and keeps in memory only the last record (index).
    So, I believe that I need to count the indexes of the JSON files and store it perhaps.
    What I mean.
    My JSON structure:
      {     "title" : "Central",
            "category": "",
        "image": "images/thumbs/models/central.png",
        "large": "auto-2f-kent-large/0.png",
            "frame": "frames-large/0.png",
             "jsonf": "auto2fk.json"
      {     "title" : "Telescopic",
            "category": "",
        "image": "images/thumbs/models/telescopic.png",
        "large": "auto-2f-til-large/0.png",
            "frame": "frames-large/0.png",
             "jsonf": "auto2ft.json"
      {     "title" : "Glass",
            "category": "",
        "image": "images/thumbs/models/glass.png",
        "large": "auto-glass-large/0.png",
            "frame": "frames-large/0.png",
             "jsonf": "autoglass.json"
    it has 3 index. And on ChildSymbol I give the attr as .attr("id", item.title);
    If I make index.length it will give me 3 as number.
    But if I make item.title.length it will count the letters of its Word, the result will be (7,10,5).
    How Can I make it to count the word itself an give me 3 as a result?

Maybe you are looking for