本文介绍了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...

推荐答案

API docs sayeth:

Container.add API docs sayeth:

这是模糊的,不是很聪明,但这是规则。调用 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()问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:15