JLabel.setBounds()方法,前提是该窗体的layout manager为null

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MF extends JFrame
    {
    public MF()
    {
    this.getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc=new GridBagConstraints();
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.anchor=gbc.WEST;
    this.getContentPane().add(new JLabel("label1"),gbc);
    gbc.gridy++;
    this.getContentPane().add(new JLabel("label2"),gbc);
    gbc.gridy++;
    gbc.gridx++;
    gbc.weightx=100;
    gbc.weighty=100;
    gbc.fill=gbc.BOTH;
    this.getContentPane().add(new JLabel(),gbc);
    this.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    });
    }
    public static void main(String args[])
    {
    MF mf=new MF();
    mf.setSize(600,600);
    mf.setVisible(true); }
    }