
-----------------------------------
Aziz
Mon Aug 15, 2005 6:08 pm

SWING: Adding components during runtime
-----------------------------------
I want to be able to have a JFrame, and then have a text field or two, then have the option for the user to add more text areas, and then more components. like this


[label] [textfield]
[label] [textfield] [add button]
        [added textfield 1] [add moved down here now] [remove]
        [added textfield 2] [add moved down here now] [remove]
[label] [textfield]


-----------------------------------
Hikaru79
Mon Aug 15, 2005 9:09 pm


-----------------------------------
JFrame's can both add(Component) and remove(Component). Simply have the removal/addition of these components (and any neccesary resizing) be done in the event listners registered to whatever buttons they press to add/remove buttons.

-----------------------------------
Aziz
Thu Aug 18, 2005 8:59 am


-----------------------------------
So what layout would be best for this? Don't certain layouts, like flow layout, just add to the end? I want to be adding/remove somewhere in the middle...? or should I use JPanels?

-----------------------------------
1of42
Sun Aug 28, 2005 8:48 pm


-----------------------------------
Using layered JPanels with various layout managers would be your best bet.

-----------------------------------
Aziz
Mon Sep 05, 2005 10:40 am


-----------------------------------
Well folks, this topic was old news, thought everything was going to work out fine, but nope! I've come to the point where the program is almost complete. Now, for these fields, I can get them to go away (by removing them) but I cannot add them! Could someone help me? I've attached the code. The problem lies in RecipeManager.java

I know it's a bit to sort through but here the rundown...

the add button fires the action command ADD. so in actionPerformed(ActionEvent e) at the bottom of the if statement under:

else if (cmd.equals(ADD))

is where my attempt is. I know its kind of confusing, but I don't have much time right now to explain much more. If you have any question just post them and I'll check back tommorow night (going to the lady's in a little bit then school starts tommorow :'()

Thanks a lot for all those who ATTEMPT to help!

-----------------------------------
rizzix
Mon Sep 05, 2005 12:33 pm


-----------------------------------
hmm instead of calling update.. call setVisible(true).. that will automatically update everything.. i mean everything.. the whole hierarchy... which is exactly what you need to do... (note the changes i've made... denoted by the "//