Take the 2-minute tour ×

I know this question was asked before, but there was no answer to it.

In Java, when I am adding components to the frame, all the elements after adding a JTextField are not rendered when the application is initialized. They are rendered after you refresh the screen e.g. minimize and maximize the screen. In the following only the textfield is rendered. It looks like some Java rendering issue.

My code is as follows:

private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 569, 321);

    txtGenerationRate = new JTextField();
    txtGenerationRate.setBounds(322, 29, 86, 20);

    lblAmountOfSolarPanelsText = new JLabel("Amount of solar panels:");
    lblAmountOfSolarPanelsText.setBounds(10, 57, 159, 14);

    frame.setVisible(true); // added it for the second time, just to make sure

Can anyone help, please?


share|improve this question
I can confirm the lagging. The first render costs a while or does not render the child component. You can find some useful information from stackoverflow.com/questions/6978017/… –  Thai Tran Jan 31 '13 at 16:27

4 Answers 4

up vote 1 down vote accepted

Try putting this at the bottom of the initialize method

frame.setBounds(100, 100, 569, 321);
share|improve this answer

At first, you should definitely read about how to use layouts: http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

The second thing, you should set your frame visible after all components are added, if you do not, you have to call repaint().

share|improve this answer

you could also try frame.revalidate(); and frame.repaint();

share|improve this answer

This seems working for me, I see both label and text field when the window first appears. The label text does not fit into label so is truncated, but apart that everything looks as expected. Maybe the wrong fragment has been removed from the code while trying to simplify it?

enter image description here

share|improve this answer

Your Answer


