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 8 of 8

Thread: Buttons Multicoloured gridlayout

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Buttons Multicoloured gridlayout

    Hi guys,

    I am new to this forum and this is my very first post, i hope someone will be able to help me.
    Please note i am a begninner so dont be too harsh on me.
    Last edited by newtolearningjava; April 26th, 2014 at 06:12 PM.


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

    Default Re: Buttons Multicoloured gridlayout

    how i can set all the buttons different colours.
    Use an array of Colors: Color[] theColorArray = {Color.red, Color.blue};
    Access each element in turn inside of the setBackground(theColorArray[theIdx]) method.
    Make sure the array has enough colors in it or make sure the index to the array: theIdx is reset to 0 when it gets to the end of the array.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Buttons Multicoloured gridlayout

    hi norm,

    i do not understand this

    Access each element in turn inside of the setBackground(theColorArray[theIdx]) method.
    Make sure the array has enough colors in it or make sure the index to the array: theIdx is reset to 0 when it gets to the end of the array.

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

    Default Re: Buttons Multicoloured gridlayout

    Do you understand arrays and how to use an index with them?

    By changing the value of the index from 0 to the length of the array-1 the code can access each element in the array in turn. (in turn means: the first one, then the second one, then the third one, etc)
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Buttons Multicoloured gridlayout

    Quote Originally Posted by Norm View Post
    Do you understand arrays and how to use an index with them?

    By changing the value of the index from 0 to the length of the array-1 the code can access each element in the array in turn. (in turn means: the first one, then the second one, then the third one, etc)
    well this was nice and quick.. i have solved it with your help. ta

    am i able to ask another related to this thread or would i need to start another thread?
    Last edited by newtolearningjava; April 13th, 2014 at 01:46 PM.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Buttons Multicoloured gridlayout

    If your new question builds on this program and still seems relevant to the thread title, sure, ask in this thread.

  7. #7
    Member
    Join Date
    Apr 2014
    Posts
    82
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Buttons Multicoloured gridlayout

    Quote Originally Posted by GregBrannon View Post
    If your new question builds on this program and still seems relevant to the thread title, sure, ask in this thread.
    oopsi i have started another thread on timer swing

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Buttons Multicoloured gridlayout

    Nah. I think you made the right decision.

Similar Threads

  1. GridLayout not working the way i want it
    By gokuball in forum AWT / Java Swing
    Replies: 3
    Last Post: August 16th, 2013, 10:02 AM
  2. Problem with GridLayout arrangement.
    By oror84 in forum AWT / Java Swing
    Replies: 1
    Last Post: May 6th, 2012, 10:46 AM
  3. GridLayout help
    By sambar89 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 26th, 2011, 11:00 PM
  4. GridLayout and size problems...
    By sambar89 in forum Object Oriented Programming
    Replies: 2
    Last Post: November 6th, 2011, 01:06 PM
  5. Images in GridLayout
    By BuhRock in forum AWT / Java Swing
    Replies: 4
    Last Post: November 5th, 2011, 12:15 AM