用GridBagLayout
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame
{
JLabel jlb =new JLabel("lb");
JButton jb =new JButton("test button");
ImageIcon icon =new ImageIcon("cat.gif");
public Test()
{
jlb.setIcon(icon);
jlb.setBorder(BorderFactory.createLineBorder(Color.red,4)); this.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx= 1;
gbc.weighty=1;
gbc.gridx=0;
gbc.gridy=0;
this.getContentPane().add(new JLabel(),gbc);
gbc.gridx=2;
gbc.gridy=2;
this.getContentPane().add(new JLabel(),gbc);
gbc.weightx= 1;
gbc.weighty=1;
gbc.gridx=0;
gbc.gridy=0;
gbc.gridheight=3;
gbc.gridwidth=3;
gbc.fill =gbc.BOTH;
this.getContentPane().add(jlb,gbc);
gbc.weightx= 0;
gbc.weighty=0;
gbc.gridx=1;
gbc.gridy=1;
gbc.gridheight=1;
gbc.gridwidth=1;
gbc.fill=gbc.NONE;
this.getContentPane().add(jb,gbc);
}
public static void main(String args[])
{
Test t=new Test();
t.setSize(400,400);
t.setVisible(true);
}
}