这是我的背景,不使用miglayout
private void initialize() {
frame = new JFrame();
frame.setSize(800, 500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel background=new JLabel(new ImageIcon("pic1.jpg"));
frame.add(background);
}
看起来非常好
但我想使用MigLayout
这是代码
private void initialize() {
frame = new JFrame();
frame.setSize(800, 500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new MigLayout("", "[800px]", "[500px]"));
JLabel background=new JLabel(new ImageIcon("pic1.jpg"));
frame.getContentPane().add(background, "cell 0 0,grow");
// also tried the following to force background "under" all cells
// frame.getContentPane().add(background);
}
看起来很糟糕
那些顶级和右白色寄宿生来自哪里?为什么图像没有完全显示?
答案 0 :(得分:5)
frame.setSize(800, 500);
包括Borders
,然后在new MigLayout("", "[800px]", "[500px]")
中用作常量的绝对协调MigLayout
大于JFrame
无/减{{1你的图像的一部分是在屏幕上绘制的,
您可以使用Borders
在frame.setLayout(new MigLayout("debug", "[400px]", "[300px]"));
frame.setLayout(new MigLayout("", "[400px]", "[300px]"));
使用了代码中的大部分详细信息
修改
删除默认差距
JFrame.pack()