你把getContentPane().add( backLabel,BorderLayout.CENTER ); 改成:
getContentPane().add( backLabel,BorderLayout.NORTH );试试

解决方案 »

  1.   

    可以把标签add到JDesktopPane上呀!
      

  2.   

    你是说这样吗theDesktop.add( backLabel,BorderLayout.CENTER); 
    结果标签 里的字显示不出来呀?
      

  3.   

    JLabel backLabel = new JLabel("Handinfo");
               getContentPane().add( backLabel,BorderLayout.NORTH);           final JDesktopPane theDesktop = new JDesktopPane();
               getContentPane().add( theDesktop,BorderLayout.CENTER);不知道是不是这样的!
      

  4.   

    可我是想把"Handinfo"这几个字放在主窗口的正中间
      

  5.   

    想问一下,你的那个Label的用途就是显示Handinfo这几个字吗?
      

  6.   

    我的本意是想在JLabel里面放一张图片作为背景呀
      

  7.   

    Label是一个组件,如果只作为显示图片用不太合适。我建议直接在Frame上画图片作为背景图,你等一会儿,我试试看。
      

  8.   

    重载JFrame中的paint(Graphics g)方法可以画图,但是刷新有问题。
        public void paint(Graphics g){
            super.paint(g);
            Font oldFont = g.getFont();
            Font font = new Font("Monospaced",1,35);
            g.setFont(font);
            g.drawString("Handinfo", getWidth()/2, getHeight()/2);
            g.setFont(oldFont);
        }
      

  9.   

    换成:
    ImageIcon image = ImageIcon("pic/pic.gif");
    g.drawImage(image.getImage(), x, y,null, null);
    如果想解决刷新的问题需要JInternalFrame实现ComponentListener,
    在内部窗体移动的时候刷新整个窗体。
      

  10.   

    非常感谢你,但是内部窗体意移动她就像一块橡皮 把图片给擦了,你告诉我
    如果想解决刷新的问题需要JInternalFrame实现ComponentListener,
    在内部窗体移动的时候刷新整个窗体。
    可我还是不知道怎么解决?
    你有时间吗?再帮帮我好吗?劳驾了?
      

  11.   

    试试这段代码:// DesktopTest1.java
    // Demonstrating JDesktopPane.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;public class DesktopTest1 extends JFrame {
        private static DesktopTest1 app = null;
        public DesktopTest1()
           {
               super( "Using a JDesktopPane" );           JMenuBar bar = new JMenuBar();
               JMenu addMenu = new JMenu( "Add" );
               JMenuItem newFrame = new JMenuItem( "Internal Frame" );
               addMenu.add( newFrame );
               bar.add( addMenu );
               setJMenuBar( bar );//背景文字           JLabel backLabel = new JLabel("Handinfo");
               getContentPane().add( backLabel,BorderLayout.CENTER );           final JDesktopPane theDesktop = new JDesktopPane();
               getContentPane().add( theDesktop );
    //           JLabel backLabel = new JLabel("Handinfo");
    //           getContentPane().add( backLabel,BorderLayout.CENTER );           getContentPane().repaint();           newFrame.addActionListener(
                       new ActionListener() {
                       public void actionPerformed( ActionEvent e ) {
                            InternalFrame frame = new InternalFrame( "Internal Frame",
                                                                true, true, true, true, app);                   frame.addComponentListener(frame);
                       Container c = frame.getContentPane();
                       JPanel panel = new JPanel();                   c.add( panel, BorderLayout.CENTER );
                       frame.setSize(300, 200);
                       frame.setOpaque( true );
                       theDesktop.add( frame );
                       frame.show();
                       ComponentEvent event = new ComponentEvent(frame,ComponentEvent.COMPONENT_MOVED);
                       panel.repaint();
                       }
                   }
                   );                   setSize( 500, 400 );
                       show();
                       repaint();
              }    public void paint(Graphics g){
            super.paint(g);
            Font oldFont = g.getFont();
            Font font = new Font("Monospaced",1,35);
            g.setFont(font);
            g.drawString("Handinfo", getWidth()/2, getHeight()/2);
            g.setFont(oldFont);
        }    public static void main( String args[] )
         {
             app = new DesktopTest1();         app.addWindowListener(
                  new WindowAdapter() {
                  public void windowClosing( WindowEvent e )
                  {
                      System.exit( 0 );
                  }
             }
             );
        }    class InternalFrame extends JInternalFrame implements ComponentListener{
            JFrame frame_ = null;
            public InternalFrame(String title, boolean resizable, boolean closable,
                                    boolean maximizable, boolean iconifiable, JFrame owner){
                super(title, resizable, closable, maximizable, iconifiable);
                frame_ = owner;
            }
            /**
             * Invoked when the component's size changes.
             */
            public void componentResized(ComponentEvent e){frame_.repaint();}        /**
             * Invoked when the component's position changes.
             */
            public void componentMoved(ComponentEvent e){frame_.repaint();}        /**
             * Invoked when the component has been made visible.
             */
            public void componentShown(ComponentEvent e){frame_.repaint();}        /**
             * Invoked when the component has been made invisible.
             */
            public void componentHidden(ComponentEvent e){frame_.repaint();}    }}
      

  12.   

    当子窗体和handinfo重叠的时候,handinfo这几个字会在子窗体之上,我把字换成图片问题又出现了。当子窗体和图片重叠的时候,图片就会把子窗体遮住