Java GUI repaint()问题? [英] Java GUI repaint() problem?

查看:206
本文介绍了Java GUI repaint()问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JFrame。这个JFrame包含一个JButton。我点击JButton并创建了10个JTextField。

I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created.

问题:
直到我通过调整窗口大小强制重绘()之后我才能看到它们。只有这样才能看到创建的JTextField。

the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created.

代码:

JPanel points = new JPanel();

//Creating the JTextFields:
for (int i=0; i<10; i++) {
    JTextField textField = new JTextField();
    points.add(textField);
}

repaint();
this.repaint();
super.repaint();
points.repaint();






谢谢 - 在for循环之后,我只是调用points.validate()并且它有效......


THANK YOU - after the for loop, I just called points.validate() and it worked...

推荐答案

Container.add API docs sayeth:

Container.add API docs sayeth:


注意:如果组件已添加到已显示的
a容器中,$ b必须在
容器上调用$ b validate才能显示新的
组件。如果添加了多个组件
,那么在所有组件都添加
之后,只需调用
一次就可以提高
效率。

Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.

这是模糊的,不是很聪明,但这是规则。调用 JComponent.revalidate

It's obscure and not very clever, but it's the rules. It may be better to call JComponent.revalidate

这篇关于Java GUI repaint()问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆