NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
aquafatz
Joined: 08 Dec 2012 Posts: 1
|
Posted: Sat Dec 08, 2012 10:07 pm Post subject: 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:
| 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!! |
|
| Back to top |
|
 |
Edson Richter Posted via mailing list.
|
Posted: Sun Dec 09, 2012 9:55 pm Post subject: Netbeans-generate number of radio buttons dynamically |
|
|
Em 08/12/2012 20:07, aquafatz escreveu:
| Quote: | 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:
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.
|
Yes, there is: in OOP, whenever you use "new ..." you create a new
object instance.
In the GUI builder, create a JPanel that will hold your dynamic objects.
Then, in your code, you will create as many objects as you want, and add
them into the panel.
| Quote: |
Any help and pointers in the direction will be greatly appreciated! Thanks!!
|
Good start point: The Java Tutorial
(http://docs.oracle.com/javase/tutorial/)
My advice is: learn Object Oriented Programming basics, then start
trying with real application.
Without learning the basic concepts, you will get in trouble all the
time, requesting help everywhere for things you don't need to (I mean,
if you miss the simple OOP concepts, how would you know that you can
create as many instances of one object?).
Kind regards,
Edson
|
|
| Back to top |
|
 |
ionuion
Joined: 03 Feb 2010 Posts: 190
|
Posted: Sun Dec 09, 2012 10:13 pm Post subject: Netbeans-generate number of radio buttons dynamically |
|
|
aquafatz,
How about using an array to hold the multiple elements? c.f. below
On Sun, Dec 9, 2012 at 12:07 AM, aquafatz <address-removed ([email]address-removed[/email])> wrote:
| Quote: | 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);
}
|
result = ..
ArrayList<String> radioButtonLabels = new ArrayList<>();
// data stuff
while (result.next()) {
cpf=result.getString("CoursePrefix");
cnum=result.getString("CourseNumber");
String cname=result.getString("CourseName");
radioButtonLables.add(cpf+" "+cnum+" "+cname);
}
// ui stuff
for (String label : radioButtonLabels) {
someJPanel.add(new JRadioButton(label);
}
Regards |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|