Java MigLayout问题
我正在尝试使用 migLayout 构建计算器 GUI,但我不熟悉这种布局。
我的问题是我的 GUI 是一条直线按钮。
1 2 3 + 4 5 6 - ... etc
I would like to get
1 2 3 +
4 5 6 -
7 8 etc...
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import java.awt.*;
public class Calculator1 {
public static void main(String args[]) {
JFrame frame = new JFrame("Calculator1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new MigLayout());
frame.add(new JTextField(" "),"wrap");
frame.add(new JButton("1"));
frame.add(new JButton("2"));
frame.add(new JButton("3"));
frame.add(new JButton("+"));
frame.add(new JButton("4"));
frame.add(new JButton("5"));
frame.add(new JButton("6"));
frame.add(new JButton("-"));
frame.add(new JButton("7"));
frame.add(new JButton("8"));
frame.add(new JButton("9"));
frame.add(new JButton("*"));
frame.add(new JButton("0"));
frame.add(new JButton("/"));
frame.add(new JButton("="));
frame.pack();
frame.setVisible(true);
}
}
I'm trying to build a calculator GUI using migLayout, but I'm not familiar with this layout.
My problem is that my GUI is a straight line of buttons.
1 2 3 + 4 5 6 - ... etc
I would like to get
1 2 3 +
4 5 6 -
7 8 etc...
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import java.awt.*;
public class Calculator1 {
public static void main(String args[]) {
JFrame frame = new JFrame("Calculator1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new MigLayout());
frame.add(new JTextField(" "),"wrap");
frame.add(new JButton("1"));
frame.add(new JButton("2"));
frame.add(new JButton("3"));
frame.add(new JButton("+"));
frame.add(new JButton("4"));
frame.add(new JButton("5"));
frame.add(new JButton("6"));
frame.add(new JButton("-"));
frame.add(new JButton("7"));
frame.add(new JButton("8"));
frame.add(new JButton("9"));
frame.add(new JButton("*"));
frame.add(new JButton("0"));
frame.add(new JButton("/"));
frame.add(new JButton("="));
frame.pack();
frame.setVisible(true);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: