Computer Science Canada SWING: Adding components during runtime |
Author: | Aziz [ Mon Aug 15, 2005 6:08 pm ] | ||
Post subject: | 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
|
Author: | Hikaru79 [ Mon Aug 15, 2005 9:09 pm ] |
Post subject: | |
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. |
Author: | Aziz [ Thu Aug 18, 2005 8:59 am ] |
Post subject: | |
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? |
Author: | 1of42 [ Sun Aug 28, 2005 8:48 pm ] |
Post subject: | |
Using layered JPanels with various layout managers would be your best bet. |
Author: | Aziz [ Mon Sep 05, 2005 10:40 am ] |
Post subject: | |
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! |
Author: | rizzix [ Mon Sep 05, 2005 12:33 pm ] | ||
Post subject: | |||
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 "//<---- here" comments)
NOTE: the method you chose to use to go about with such functionality is not the ideal way of going about with it... the ideal way would involve you creating a new container component... and adding in the functionality your self.. of course now that's a lot of work, comparitively, but it will allow you to reuse the mechanism elsewhere easily... another way of doing this.. and probably the preferable way,, would invovle using the JList component... nevertheless your current solution "will" work.. |
Author: | Aziz [ Tue Sep 06, 2005 9:38 am ] |
Post subject: | |
And that is why you're the master and I am the student Well I never would have thought about that. But I still don't quite understand. If I can figure it out I'd prefer to do it that way. But what do you mean with a JList component? |
Author: | rizzix [ Wed Sep 07, 2005 12:05 am ] |
Post subject: | |
my mistake.. apparently the JList does not support in-cell-editing.. i.e you can put a button in there for a cell but you can't expect it to receive events... in other words.. it will render the button but the button will not function... hmm.. i know the JTable component allows in-cell-editing.. i'll look into how such functionality can be accomplished using the Jtable component, and come back to you later.. |