前辈,请帮个忙写一个设置界面背景的源代码,谢谢!!!

解决方案 »

  1.   

    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;public class Expand
    {  protected Shell shell;  /**
       * Launch the application.
       * @param args
       */
      public static void main(String[] args)
      {
        try
        {
          Expand window = new Expand();
          window.open();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }  /**
       * Open the window.
       */
      public void open()
      {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed())
        {
          if (!display.readAndDispatch())
          {
            display.sleep();
          }
        }
      }  /**
       * Create contents of the window.
       */
      protected void createContents()
      {
        shell = new Shell();
        shell.setSize(450, 300);
        shell.setText("SWT Application");
        Image image = new Image(shell.getDisplay(), getClass().getResourceAsStream("eclipse48.png"));
        shell.setBackgroundImage(image);
      }}需要一个图片eclipse48.png
    放在类的文件夹下面
      

  2.   

    import org.jdesktop.swingx.painter.ImagePainter;
    import org.jdesktop.swingx.JXPanel;JXPanel container = new JXPanel();
    container.setBackgroundPainter(new ImagePainter(ImageIO.read(....)));
    container.add(...);frame.setContentPane(contaienr);
    使用了SwingX库。