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: JButtons behavior in ActionListener

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default JButtons behavior in ActionListener[solved]

    Hi
    I have a problem with a program i am writing.

    Not the problem:I have jButtons in a JPanel and depending which of 3 JCheckbox's is checked, the number of buttons changes. I have them in a Buttongroup. I have also programmed a JMenu that autochecks the checkboxes through an ActionListener and the number of boxes relative to the selected checkbox works fine thanks to the ItemListener.

    The real Problem:I need the buttons to behave differently depending on how many there are in the panel.
    Ex: button 4 subtracts 2 if 4 buttons are present but subtracts 1 if 9 buttons are present. Is there a way to code this? and if so...how? If given 1 example, I can probably figure the rest out. Any help you can give me would be greatly appreciated.
    Last edited by QuincyOrsot; April 29th, 2012 at 06:58 PM. Reason: solved


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,976
    Thanks
    52
    Thanked 2,270 Times in 2,242 Posts

    Default Re: JButtons behavior in ActionListener

    The Container class has a methods you can call to get information about the components it contains.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,684
    Thanks
    25
    Thanked 333 Times in 309 Posts

    Default Re: JButtons behavior in ActionListener

    If your buttons are in a ButtonGroup, you can call the getButtonCount() method (ButtonGroup (Java Platform SE 6))
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. The Following User Says Thank You to aussiemcgr For This Useful Post:

    QuincyOrsot (April 26th, 2012)

  5. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JButtons behavior in ActionListener

    Thats helps dramatically....It gives me a direction to follow

Similar Threads

  1. ActionListener inside another ActionListener
    By kpat in forum AWT / Java Swing
    Replies: 6
    Last Post: March 28th, 2012, 03:43 PM
  2. JButtons not showing
    By Shaybay92 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 27th, 2011, 07:42 AM
  3. GUI: JButtons aren't visible until clicked
    By Staticity in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 7th, 2011, 02:49 PM
  4. help with JFrame, drawing, and JButtons
    By Khoatic in forum AWT / Java Swing
    Replies: 1
    Last Post: November 18th, 2010, 11:34 PM
  5. JTables with JButtons, I'm overlooking something
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2010, 11:30 AM