在JPanel中添加的组件是变化的,比如我按一个按钮后将JPanel中的布局和组件改变了,怎么让它显示出来?
8 个解决方案
#1
执行repaint()方法 如果还不行 执行validate()方法
#2
重写paintComponent()方法
#3
1楼的说的那个validate()方法还真管用,怎么repaint()方法不行呢,不也是重画?
#4
validate()是容器类的方法,repaint只是管重绘自己,如果容器里面的部件有添加删除,需要用validate方法验证
问题解决了就及时结贴给分喽
问题解决了就及时结贴给分喽
#5
使用JPanel中的
updateUI()方法,
public void updateUI()
Resets the UI property with a value from the current look and feel.
public void updateUI()
Resets the UI property with a value from the current look and feel.
#6
#7
#8
确定“repaint只是管重绘自己”吗?repaint()貌似调用paint()而,paint()又依次委派给paintComponent(), paintBorder(), paintChildren() 3个方法,其中paintComponent()委派给该Component的updateUI, 最后由各自的UI类来实现。我说的有没有问题?
#1
执行repaint()方法 如果还不行 执行validate()方法
#2
重写paintComponent()方法
#3
1楼的说的那个validate()方法还真管用,怎么repaint()方法不行呢,不也是重画?
#4
validate()是容器类的方法,repaint只是管重绘自己,如果容器里面的部件有添加删除,需要用validate方法验证
问题解决了就及时结贴给分喽
问题解决了就及时结贴给分喽
#5
使用JPanel中的
updateUI()方法,
public void updateUI()
Resets the UI property with a value from the current look and feel.
public void updateUI()
Resets the UI property with a value from the current look and feel.
#6
#7
#8
确定“repaint只是管重绘自己”吗?repaint()貌似调用paint()而,paint()又依次委派给paintComponent(), paintBorder(), paintChildren() 3个方法,其中paintComponent()委派给该Component的updateUI, 最后由各自的UI类来实现。我说的有没有问题?