本帖最后由 lanying2017 于 2011-04-11 14:28:38 编辑

解决方案 »

  1.   

    import java.awt.Rectangle;import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class Image extends JFrame {
    JPanel     jpanel;
    JLabel     label;
    ImageIcon    icon;
    public Image(){
    icon = new ImageIcon("pond.png");
    label = new JLabel(icon);
    label.setLayout(null);
    label.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());

    jpanel = new JPanel();
    jpanel.setLayout(null);
    jpanel.setBackground(Color.GRAY);
    jpanel.add(label);
    jpanel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());

    this.setTitle("test");
    this.add(jpanel);
    this.setVisible(true);
    this.pack();
    this.setBounds(new Rectangle(10,10,icon.getIconWidth(),icon.getIconHeight()));
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String [] args){
    new Image();
    }

    }
    主要是紅色部份的設置