blob: 37f19640e38a63a2e55006b81fbc6155662dfc71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package net.miginfocom.examples;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
/**
*/
public class Example01
{
private static JPanel createPanel()
{
JPanel panel = new JPanel(new MigLayout());
panel.add(new JLabel("First Name"));
panel.add(new JTextField(15));
panel.add(new JLabel("Surname"), "gap unrelated"); // Unrelated size is resolved per platform
panel.add(new JTextField(15), "wrap"); // Wraps to the next row
panel.add(new JLabel("Address"));
panel.add(new JTextField(), "span, growx"); // Spans cells in row and grows to fit that
return panel;
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
JFrame frame = new JFrame("Example 01");
frame.getContentPane().add(createPanel());
frame.pack();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
|