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: Netbeans-generate number of radio buttons dynamically

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

    Default Netbeans-generate number of radio buttons dynamically

    I'm creating a databse application with SQL server management as the back end and the GUI in Netbeans. Based on the number of rows or tuples retrieved from the databse, I want to create those many radio buttons. Currently I've just come to this:

    result = select.executeQuery("SELECT .......");
     
    while(result.next())
    {
         cpf=result.getString("CoursePrefix");
         cnum=result.getString("CourseNumber");
         String cname=result.getString("CourseName");
         jRadioButton1.setText(cpf+" "+cnum+" "+cname);
     
     }

    So, is there a way to to create radio buttons dynamically (something like jRadioButtoni.setText(cpf+" "+cnum+" "+cname)) where i is the number of tuples returned by the query in result.
    Also, in the GUI builder I have to drag and drop the swing controls. I cannot declare teh components via the source code.

    Any help and pointers in the direction will be greatly appreciated! Thanks!!


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Netbeans-generate number of radio buttons dynamically


  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    7
    My Mood
    Nerdy
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Netbeans-generate number of radio buttons dynamically

    well it can be done like this:
    Create a jscrollpane
    add panel to it
    Set the layout of panel to your desired layout
    connect to database and get the number of rows or tuples.
    call addRadioBtn(your jpanel's variable, no. of rows or tupples)
    void addRadioBtn(jPanel jp,int len)
    {
    	jRadiobutton jr[] = new jRadioButton[len];
    	for(int i =0; i<len; ++i)
    	{
    		jr[i] = new jRadiobutton();
    		jp.add(jr[i]);
    	}
    }
    Hope this help.

Similar Threads

  1. [SOLVED] set specific location for radio buttons
    By nosxlimit in forum Java Theory & Questions
    Replies: 3
    Last Post: June 18th, 2012, 08:15 AM
  2. [SOLVED] Creating Dynamically Radio Buttons, Labels
    By Onur in forum Java Theory & Questions
    Replies: 15
    Last Post: August 25th, 2011, 08:39 AM
  3. Help with radio buttons and results.
    By Bewitched1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 3rd, 2011, 04:01 PM
  4. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM
  5. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 05:39 AM

Tags for this Thread