Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Swing buttons

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Swing buttons

    I have a problem
    I made a grid of buttons (6,6)
    but now i want to give some of the buttons a different color.
    i dont know how because i made the buttons with a for loop ofcourse


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Swing buttons

    If the buttons are in an array, you can access them by using indexes.
    This element of the array: theArray[row][col] is a button and can be used to call button methods:
    theArray[row][col].aButtonMethod()
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Swing buttons

    right now, they are in a forloop

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Swing buttons

    The array would need to be defined outside of a method if you want other methods to be able to access it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Swing GUI: Using buttons from a different classfile in ActionListener
    By VikingCoder in forum Java Theory & Questions
    Replies: 1
    Last Post: November 6th, 2012, 10:56 AM
  2. Java swing buttons are flickering in windows 7 environment
    By javasam in forum Member Introductions
    Replies: 1
    Last Post: February 17th, 2011, 09:51 AM
  3. Java swing buttons are flickering in windows 7 environment
    By javasam in forum AWT / Java Swing
    Replies: 1
    Last Post: February 14th, 2011, 12:13 PM
  4. [SOLVED] Problem with swing-buttons
    By Minken in forum AWT / Java Swing
    Replies: 8
    Last Post: October 15th, 2010, 09:20 PM
  5. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM