Well, I managed to do what follows. By clicking the button, Abels are added to the screen.
import java.swing.List;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class CriaBotoes {
private final JFrame jf;
private final List<JLabel> lista;
public static void main(String[] args) {
EventQueue.invokeLater(CriaBotoes::new);
}
public CriaBotoes() {
jf = new JFrame("Teste");
jf.setBounds(10, 10, 700, 700);
jf.setLayout(null);
JButton bt = new JButton("Novo label");
jf.add(bt);
bt.setBounds(10, 10, 100, 30);
lista = new ArrayList<>();
bt.addActionListener(e -> adicionarLabel());
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jf.setVisible(true);
}
public void adicionarLabel() {
int n = lista.size() + 1;
String name = "cor " + n;
JLabel label = new JLabel(name);
jf.add(label);
label.setBounds(10, n * 20 + 20, 150, 20);
lista.add(label);
}
}
JLabel label = new JLabel();
. Then just set a position, a size, a text and add the in the parent control.– Jéf Bueno
how would it look in the code? this would all be inside the add button?
– Carlos Diego
Where you want, whether you will be in the button action or create a method you choose. A question: you are using some layout?
– Jéf Bueno
JLabel label = new JLabel(text); 
 label.setName(name); 
 label.setBounds(x, y, 50, 50);
?– Carlos Diego
missing add to the frame in question,
teuPanel.add(label);
something like this, if you’re adding in real time, you may need to update the frame,teuPanel.revalidate();
teuPanel.repaint();
teuPanel.pack();
– jsantos1991