不应该,建议你覆盖repaint方法,打出一些log看看

解决方案 »

  1.   

    try the getParent().validate()
      

  2.   

    JPanel pane=new JPanel();
    JScrollPane scrollPane=new JScrollPane(pane);
    JButton button=new JButton();
    mainPanel.setLayout(null);
    mainPanel.add(button);
    mainPanel.add(scrollPane);
    scrollPane.setBounds(x,y,width,height);
    button.addActionListener(new ActionListener{
       public void actionPerformed(ActionEvent e){
           pane.add(new JButton("test1"));
           pane.repaint();
           scrollPane.repaint();
           mainPanel.repaint();
       }
    });
    当我单击button时,发现要再单击一下scrollPane,那个test1 button才会出现,不知道应该怎样做。
    上面的程序是我把我的程序简化了一下,临时写的,可能有些问题,没有编译过。各位包涵。
    多谢各位的帮助
      

  3.   

    有没有高手帮帮忙啊。thanks