Adding dynamic fields to java / swing form

I am new to java and use netbeans to create a user interface.

What I'm trying to do is ...

in the shape of. there is jComboBox and JTextField where the user can enter the service that he chooses and observation. So far, so good. JComboBox populated from database records.

The problem is that the user can enter N different services at the same time (too many to be a bunch of flags). I thought to add a "[+]" button (along with a "[-]" to delete). Thus, users press [+], and another new line with jcombobox + jtextfield is displayed directly below the previous ones.

I am stuck on this issue. On the ActionPerformed [+] button, I just can't clone and add previous nodes. Any idea on how to proceed.

My background is webdev. Doing this with javascript would be very fast. Well, I think you already know what I'm trying to do. Waiting for some kind of light. thank.

+3
source share
2 answers

You are on the right track. Here are some source code to give you some ideas. alt textalt text

, EntryList ; "/", / . "/", , ( )

; , , . , .

+6

, , . Box . , , . - :

JComboBox checkBox = new JComboBox(...);
JTextField textField = new JTextField(...);
JPanel row = new JPanel();
row.add( comboBox );
row.add( textfield );
mainPanel.add( row );
mainPanel.revalidate();
+1

Source: https://habr.com/ru/post/1783283/


All Articles