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

Thread: removing all buttons from buttongroup

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

    Default removing all buttons from buttongroup

    I'm trying to remove all the buttons from a buttonGroup but I'm having problems with the argument of the remove() method defined in the API:

    for(int i = 0; i < RadioButtonsGroup.getButtonCount(); i++){
     
     
    		RadioButtonsGroup.remove......???
     
    	}

    It seems there is no method to remove a button by index, any suggestion for a beginner?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: removing all buttons from buttongroup

    RadioButtonsGroup.remove ( AbstractButton ab );
    How do you store your buttons after creating them? In an array? ArrayList? Iterate the collection and remove index for each.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: removing all buttons from buttongroup

    the buttons are created from a List returned from port.getAvailablePorts(): (method from rxtx serial class)

    for (int i = 0; i < port.getAvailablePorts().size(); i++){
     
     
    	JRadioButtonMenuItem e = new JRadioButtonMenuItem(port.getAvailablePorts().get(i));
     
    	RadioButtonsGroup.add(e);
     
    	menuItem.add(e);}

    when I want to refresh the serial ports list, first I need to clear the button group, then rebuild it with the new buttons, but I can't clear it using remove() with values from port.getAvailablePorts() because they can change at any time.

    I will try to store the buttons in a separate ArrayList, so I will feed the remove() method with its values, then clear the Arraylist, fill the ArrayList with the new values from port.getAvailablePorts(), create and add the buttons to the button group.

Similar Threads

  1. Help removing JFrame inheritance
    By SendBorg in forum AWT / Java Swing
    Replies: 3
    Last Post: January 28th, 2012, 07:10 PM
  2. Help: Bug with removing data from a Hash Map
    By seabeach in forum Collections and Generics
    Replies: 4
    Last Post: August 11th, 2011, 11:54 AM
  3. Arraylist removing element
    By Stn in forum Loops & Control Statements
    Replies: 6
    Last Post: January 9th, 2011, 07:14 PM
  4. Removing objects from a hashSet
    By JohnTor in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2010, 02:03 PM
  5. Removing the middle cell
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 7th, 2010, 12:35 PM