In my form there is a JComboBox
, and depending on what is selected I would like to add some additional rows (labels and JTextFields
) to the form just below the JComboBox
and push the rest of the fields that many rows lower. Is this possible with JGoodies DefaultFormBuilder
(or any other technique), and if so how?
Asked
Active
Viewed 944 times
1

Andrew Thompson
- 168,117
- 40
- 217
- 433

Stephane Grenier
- 15,527
- 38
- 117
- 192
-
Probably just using the builder to add more fields and calling `revalidate()` on the parent container should do it. – Andrew Thompson Dec 16 '12 at 02:21
-
DefaultFormBuilder is a third party framework to create JPanel forms, and you can't just add more fields and call revalidate(). It does not work like this at all. – Stephane Grenier Dec 16 '12 at 02:26
-
What happened when you tried it? – Andrew Thompson Dec 16 '12 at 02:27
-
Are you familiar with the JGoodies Forms library/framework? You cannot add a field and specify the row. It's not something that's even available in the API: http://www.jarvana.com/jarvana/view/com/jgoodies/forms/1.2.0/forms-1.2.0-javadoc.jar!/index.html?com/jgoodies/forms/builder/DefaultFormBuilder.html – Stephane Grenier Dec 16 '12 at 02:32
-
My bad, I missed the fact you wanted to **insert** as opposed to **append** components. In that case, you might put an empty panel immediately after the combo. and add the new components into that. – Andrew Thompson Dec 16 '12 at 02:42
-
Yes but doing that will leave a blank row when it's not needed. That doesn't shift the rows down, it just puts an empty row. And if there are multiple fields/rows, then this could be a lot of blank space. – Stephane Grenier Dec 16 '12 at 02:50
-
Btw, if you're the one who downvoted this question, you may want to adjust your vote... – Stephane Grenier Dec 16 '12 at 02:50
-
1*"if you're the one who downvoted this question"* Nope. Don't know why it was down-voted. – Andrew Thompson Dec 16 '12 at 02:51
1 Answers
1
As far as I can tell there is no proper way. So what I ended up doing was creating a JPanel for each field with a BoderLayout. Then I added the max number of fields I would ever need to the form. Then when I needed to move fields down, I would remove them from the allocated JPanel's and push them to the ones below in a loop.
Not exactly the prettiest or most elegant but I couldn't find another solution at all...

Stephane Grenier
- 15,527
- 38
- 117
- 192