这样试试看行不行.从这开始test.setLayout(bl);用这些替换一下
Container c=test.getContentPanel();
c.setLayout(bl);
c.add(new Button("North"),BorderLayout.NORTH);
c.add(new Button("South"),BorderLayout.SOUTH);
c.add(new Button("West"),BorderLayout.WEST);
c.add(new Button("East"),BorderLayout.EAST);

解决方案 »

  1.   

    FrameTest test=new FrameTest("This is Title");
        test.setLocation(100,100);
        Button button=new Button("This is a Button");
        button.setVisible(true);
        BorderLayout bl=new BorderLayout(0,5);
        test.setLayout(bl);
        test.add(new Button("North"),BorderLayout.NORTH);
        test.add(new Button("South"),BorderLayout.SOUTH);
        test.add(new Button("West"),BorderLayout.WEST);
        test.add(new Button("East"),BorderLayout.EAST);
        test.setSize(300,300);
        test.setVisible(true);
        Dialog dlg=new Dialog(test,"attion",true);
        dlg.setSize(240,150);
        //dlg.show();
      

  2.   

    to Doctor: 他用的是Frame,不是JFrame,所以是不用getContentPane()的。我觉得应该是在那个button.setVisible()那里吧,一个组件应该在容器中显示的,那个button还没有加到容器中,那么该在哪里显示呢?不知道运行时有没有报错呢?我暂时没有编译环境,所以不能帮你测试,呵呵~~你可以试一下!
      

  3.   

    put the following statement to last line    test.setVisible(true);
      

  4.   

    问题仅仅一个:不ButtonObjest.setVisuable(true);
    这一句代码一定要有!
      

  5.   

    只需要把:
    test.setVisible(true);这句放到你添加Button完之后就可以了,而且一般都应该这样:
    在做完所有的添加后才显示!
    ///////////////////////////////
    说来我发现这样解决的过程有些搞笑,我测试了你的代码,偶然点了最大化按钮,发现你的Button显示出来了,在还原还是有。而点最小化在还原却还是没有,这很奇怪,看来他们的处理是不一样了。后来想想虽然解决了你的问题,可是更深我还没有搞清楚,有知道的吗,出招吧。
      

  6.   

    我今天也测试了你的代码,楼上说的没有错。我没有点最大化按钮,只要我稍微改变一下窗口的大小按钮就显示出来了,即使不改变窗口的大小,鼠标移到边框变成改变大小指针时,点击一下就显示了。我想这是重画的问题吧,组件虽然已经加到容器中,但是你是先显示容器再添加组件的,窗口没有重画所以就没有显示组件了。但又很奇怪,怎么我调用Frame的repaint()强制重画却没有效果!还有我对repaint这个方法不是很了解,请高手指点!
      

  7.   

    正如上述所说:我测试了你的代码,将test.setvisible();放在添加按钮之后就可以了
    另外你的frame 不能关闭,我在main ()中加了如下的语句,能够关闭你的frame
    test.addWindowListener(new WindowAdapter(){public void windowClosing (WindowEvent e){
            System.exit(0);
          }
        });
      

  8.   

    你在test中添加完button后需要再执行test.setVisible(true);
      

  9.   

    在添加完之后加上test.setVisible(true);或test.show();或test.pack();都可以.原因我想是这样的.下面是api里的解释:pack
    public void pack()
    Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
    show
    public void show()
    Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. If the Window is already visible, this will bring the Window to the front.多谢 hehecafe给我提出错误.