Results 1 to 4 of 4
  1. #1
    Moddy is offline Member
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    Default JButtonGroup; add() method not found?

    [Edit: Sorry about the title; I mean "ButtonGroup" - NOT JButtonGroup!]

    Basically I've just started to mess about with Swing and I am finding it pretty good! But I have just encountered a problem with ButtonGroup.

    From what I have read I need to use its add() method to add JButton's into it. Like this...

    Java Code:
    		/* Create a ButtonGroup */
    		ButtonGroup fruit = new ButtonGroup();
    
    		/* Create 3 buttons. */
    		JRadioButton rad1 = new JRadioButton("Apples");
    		JRadioButton rad2 = new JRadioButton("Pears");
    		JRadioButton rad3 = new JRadioButton("Oranges");
    
    		/* Add our RadioButtons to our ButtonGroup */
    		fruit.add(rad1);
    		fruit.add(rad2);
    		fruit.add(rad3);
    
    		/* Then add our RadioButtons to our container */
    		contentArea.add(rad1);
    		contentArea.add(rad2);
    		contentArea.add(rad3);
    Now I go to compile that and get this error..

    ButtonGroup.java:31: error: Can't find method ‘add(Ljavax/swing/JRadioButton;)’ in type ‘ButtonGroup’.
    fruit.add(rad1);
    ^
    ButtonGroup.java:32: error: Can't find method ‘add(Ljavax/swing/JRadioButton;)’ in type ‘ButtonGroup’.
    fruit.add(rad2);
    ^
    ButtonGroup.java:33: error: Can't find method ‘add(Ljavax/swing/JRadioButton;)’ in type ‘ButtonGroup’.
    fruit.add(rad3);
    ^
    3 errors
    Has the add() method since been removed or am I reading something outdated?

    Help would be much appreciated! Thanks =]
    Last edited by Moddy; 07-11-2008 at 06:04 PM. Reason: ButtonGroup; NOT JButtonGroup - woops!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    What version of javac are you using?
    Compiles OK for me with java 1.4.1.

  3. #3
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default HERE IS AN EXAMEPLE TO CLARIFY JButtonGoup Keyword

    friend here is some code that my help u

    the first java code will say the importance of ButtonGroup statement and the second code will say u what happens if the GroupButton is removed.

    krishna


    /////////////////////////////////////////////////////////////////////////////

    import java.awt.*;
    import javax.swing.*;

    class FrameBuild //extends AbstractAction
    {
    public static void main(String args[])
    {
    JFrame frame = new JFrame("SQL Command Exicuter");
    frame.setSize(550,375);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);



    JMenuBar mb = new JMenuBar();

    TextArea txtarea = new TextArea("Your Command Here",10,35,TextArea.SCROLLBARS_BOTH);

    frame.setJMenuBar(mb);

    JMenu JMfile = new JMenu("File");
    JMenu JMedit = new JMenu("Edit");
    JMenu JMsql = new JMenu("SQLCommand");
    JMenu JMtools = new JMenu("Tools");

    JButton JBsubmit = new JButton("Submit");
    JButton JBcancle = new JButton("Cancel");
    JRadioButton JRyes = new JRadioButton("Save The SQL Command");
    JRadioButton JRno = new JRadioButton("Dont Save The SQL Command");

    ButtonGroup RBGroup = new ButtonGroup(); // creating the button group


    mb.add(JMfile);
    mb.add(JMedit);
    mb.add(JMsql);
    mb.add(JMtools);

    frame.add(txtarea);

    frame.add(JBsubmit);
    frame.add(JBcancle);

    RBGroup.add(JRyes); // adding the radio button to ButtonGroup
    RBGroup.add(JRno); // same thing, adding another radio Button to ButtonGroup

    /* unless u add the radiobuttons to the ButtonGroup
    u wont get the exact functionally and porpouse of the radio buttons */



    frame.add(JRyes);
    frame.add(JRno);




    frame.setLayout(new FlowLayout());


    frame.setVisible(true);
    }

    }



    //////////////////////////////////////////////////////////////////////////

    import java.awt.*;
    import javax.swing.*;

    class FrameBuild //extends AbstractAction
    {
    public static void main(String args[])
    {
    JFrame frame = new JFrame("SQL Command Exicuter");
    frame.setSize(550,375);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);



    JMenuBar mb = new JMenuBar();

    TextArea txtarea = new TextArea("Your Command Here",10,35,TextArea.SCROLLBARS_BOTH);

    frame.setJMenuBar(mb);

    JMenu JMfile = new JMenu("File");
    JMenu JMedit = new JMenu("Edit");
    JMenu JMsql = new JMenu("SQLCommand");
    JMenu JMtools = new JMenu("Tools");

    JButton JBsubmit = new JButton("Submit");
    JButton JBcancle = new JButton("Cancel");
    JRadioButton JRyes = new JRadioButton("Save The SQL Command");
    JRadioButton JRno = new JRadioButton("Dont Save The SQL Command");

    // ButtonGroup RBGroup = new ButtonGroup(); // creating the button group


    mb.add(JMfile);
    mb.add(JMedit);
    mb.add(JMsql);
    mb.add(JMtools);

    frame.add(txtarea);

    frame.add(JBsubmit);
    frame.add(JBcancle);

    // RBGroup.add(JRyes); // adding the radio button to ButtonGroup
    // RBGroup.add(JRno); // same thing, adding another radio Button to ButtonGroup

    /* unless u add the radiobuttons to the ButtonGroup
    u wont get the exact functionally and porpouse of the radio buttons */



    frame.add(JRyes);
    frame.add(JRno);




    frame.setLayout(new FlowLayout());


    frame.setVisible(true);
    }

    }

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

    Default

    Question for the original poster: Do you have another class that you've created that is in the current classpath and has been named "ButtonGroup"? Please search your Java folders, because if you have this, it could be causing the behavior that you are seeing now.

Similar Threads

  1. struts No Collection Found
    By orchid in forum Web Frameworks
    Replies: 3
    Last Post: 02-18-2010, 05:37 PM
  2. GeoPoint Not found
    By nvidia in forum NetBeans
    Replies: 2
    Last Post: 05-28-2008, 09:31 PM
  3. could not be found in the registry
    By alam99 in forum Eclipse
    Replies: 0
    Last Post: 01-08-2008, 08:21 AM
  4. 404 Not Found
    By mary in forum Java Servlet
    Replies: 5
    Last Post: 11-07-2007, 10:15 AM
  5. ConnectException not found
    By tamayo in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 08:23 AM

Posting Permissions

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