import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.*;
public class FormLayoutExample extends JFrame {
public FormLayoutExample() {
setTitle("FormLayout Example");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String columnSpec = "right:pref, 4dlu, pref:grow";
String rowSpec = "pref, 4dlu, pref";
FormLayout layout = new FormLayout(columnSpec, rowSpec);
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
builder.addLabel("Label 1", CC.xy(1, 1));
builder.add(new JTextField(), CC.xy(3, 1));
builder.addLabel("Label 2", CC.xy(1, 3));
builder.add(new JTextField(), CC.xy(3, 3));
add(builder.getPanel());
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
FormLayoutExample example = new FormLayoutExample();
example.setVisible(true);
});
}
}
```
这些示例代码演示了如何使用 MigLayout 和 FormLayout 来创建不同风格的用户界面。