// This code example is created for educational purpose // by Thorsten Thormaehlen (contact: www.thormae.de). // It is distributed without any warranty. import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; class MyGuiApplet extends JApplet{ public void createGUI() { setSize(320, 240); String[] labels = {"Firstname: ", "Lastname: ", "Student ID: ", "Enrolled since: "}; Container contentPane = getContentPane(); contentPane.setLayout(new SpringLayout()); for (int i = 0; i < labels.length; i++) { JLabel label = new JLabel(labels[i], JLabel.TRAILING); contentPane.add(label); JTextField textField = new JTextField(10); label.setLabelFor(textField); contentPane.add(textField); } SpringUtilities.makeCompactGrid(contentPane, labels.length, 2, 5, 5, 5, 5); setVisible(true); } } public class MySpringLayoutApplet extends MyGuiApplet { public void init() { try{ javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch(Exception e) { System.err.println("Failed to display the GUI"); } } }