问题一 有的时候,问什么在JPanel里面不掉用validate(),组件就显示不出来?问题二 问什么用鼠标改变窗体大小,组件就显示出来了?谢谢

解决方案 »

  1.   

    validate()方法是使得某个区域的显示无效,对于无效的显示区域,会重新渲染,组件就出来了
    用鼠标一改变窗体的大小,整个窗体的区域都变成了无效,也会重新渲染
      

  2.   

    validate类似于刷新的功能吧  比如我以前在JTable的对象里添加了一些东西  我想再显示最新的表的话 就validate一下  这样我想势必有可能把别的控件挡住了  我是这么理解的
      

  3.   

    Validates this container and all of its subcomponents.The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.If this Container is not valid, this method invokes the validateTree method and s this Container as valid. Otherwise, no action is performed. 
      

  4.   

    当你在组件已经显示在屏幕上的时候往里面添加新的组件时,需要调用validate()方法
    因为在添加组件时是不会重绘组件的,新的组件只有当重新绘制的时候才会显示出来
    用鼠标改变大小,组件当然就会重新绘制,所以新添加的组件就显示出来了
      

  5.   

    可以举个例子吗,来说明:当你在组件已经显示在屏幕上的时候往里面添加新的组件时,需要调用validate()方法