Results 1 to 7 of 7

Thread: JButton color

  1. #1
    Bimz is offline Member
    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    0

    Default JButton color

    i was wundering if a JButton can be set to Enabled(false) and give it a background color...

    also is it possible to give a JButton a background color at all? if so please give example :)

    much appreciated,
    Bimz

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: JButton color

    There are methods to do those things. Have you read the API doc for the JButton class?

  3. #3
    Bimz is offline Member
    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    0

    Default Re: JButton color

    no... ill go look at that, thanks :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: JButton color

    One way to do what you want is to swap the JButton's icon and rather than disable the JButton, disable its ActionListener (have an if block that calls return if you want the button to not do anything).

  5. #5
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default Re: JButton color

    hmmmm....
    you can set the background of JButton in both cases when JButton is enabled or disabled...
    try this....

    buttonname.setBackground(Color.RED);

  6. #6
    gauravmanral's Avatar
    gauravmanral is offline Gaurav Manral
    Join Date
    Jul 2011
    Location
    Delhi
    Posts
    37
    Rep Power
    0

    Default Re: JButton color

    try with different colors...

  7. #7
    Bimz is offline Member
    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    0

    Default Re: JButton color

    yer i tried that but it doesnt work... i think its coz im on a mac

Similar Threads

  1. RGB to Color Name
    By zit1343 in forum Advanced Java
    Replies: 12
    Last Post: 04-24-2011, 06:02 PM
  2. [COLOR="Navy"]execute .bat file in mysql [/COLOR]
    By msankar.ravi in forum Networking
    Replies: 0
    Last Post: 02-24-2010, 04:27 AM
  3. Replies: 4
    Last Post: 03-21-2009, 05:48 PM
  4. Disabled JButton font color
    By p900128 in forum Advanced Java
    Replies: 1
    Last Post: 07-24-2008, 08:16 AM
  5. JButton onClick change color background
    By behrk2 in forum AWT / Swing
    Replies: 6
    Last Post: 07-09-2008, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •