In che senso ,questo di crea un jpanel con all'interno label , se vuoi che il nome del label provenga da un array di Stringhe con i nomi ad esempio Guarda questa classe:
codice:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
public class Prova1 extends JFrame {
private JPanel contentPane;
private JLabel label1,label2 ;
private static String[] nome={"nuovalabel1","nuovalabel2"};
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Prova1 frame = new Prova1();
frame.setVisible(true);
// frame.label1.setText(nome[0]);
// frame.label2.setText(nome[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Prova1() {
setTitle("titolo della finestra");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
label1 = new JLabel("Jlabel1");
label1.setBounds(26, 79, 272, 15);
contentPane.add(label1);
label2 = new JLabel("jlabel2");
label2.setBounds(26, 156, 242, 15);
contentPane.add(label2);
}
}
Prova ad eseguire questa classe e poi a togliere i commenti nel main che servono a settare il nome delle label....