Results 1 to 4 of 4
  1. #1
    aquafatz is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    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:


    Java Code:
    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
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Netbeans-generate number of radio buttons dynamically

    Go through the result set and create the radio buttons (ie use "new") with the name you want. Then add them to whatever container you want.

    in the GUI builder I have to drag and drop the swing controls. I cannot declare teh components via the source code
    The gui builder does its thing at design time (ie code writing time), not at runtime which is when you actually discover the number the buttons you want. It's not looking good for the gui builder!

    (Maybe a NB aware component exists. From the recesses of my memory I seem to remember Delphi had a control that would create a bunch of radio buttons based on an array of strings. Someone might have written a similar component that can be installed onto the palette of your gui builder. My guess is that it would be faster to write your own code than search about for someone else's and then wrestle with their documentation - or lack of it. Letting go of the gui builder does take some work, but is worth it.)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Netbeans-generate number of radio buttons dynamically

    Also at javaprogrammingforums.com, forums.netbeans.org and stackoverflow.com

    @OP: If you are going to start a discussion at various places its helpful and polite to post the locations of those places. That way everyone taking part in a discussion knows what else is being said.

    Bear in mind that some people will not participate in a discussion if they think they might be wasting their time on something that has been dealt with elsewhere.
    Last edited by pbrockway2; 12-09-2012 at 01:57 AM.

  4. #4
    aquafatz is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: Netbeans-generate number of radio buttons dynamically

    Hmm...so basically Netbeans does not the functionality of dynamically creating components.
    I'll work on the code without the GUI builder.
    Thanks!

    And sorry about that...I really wanted to know how to do it. I had seen it in some tutorial but when I went back to search for it, I couldn't find it.
    Maybe I just confused the tutorial for something else.

Similar Threads

  1. Help help.radio buttons
    By 10e5x in forum New To Java
    Replies: 3
    Last Post: 01-04-2011, 07:10 PM
  2. Help with Radio Buttons
    By miguelms19 in forum AWT / Swing
    Replies: 3
    Last Post: 06-29-2010, 07:49 PM
  3. How can i setString when i use radio buttons?
    By Tahorn in forum AWT / Swing
    Replies: 4
    Last Post: 02-16-2010, 02:03 PM
  4. [SOLVED] Radio Buttons
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-04-2009, 03:44 PM
  5. How to use Radio Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:26 PM

Tags for this Thread

Posting Permissions

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