简体   繁体   中英

Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

I have a Java program that creates a JFrame, a JPanel, and several JTextAreas. I set the text of the JTextAreas and then add them to the JPanel. When the program loads, I only see the empty JFrame.

However, if I maximize, or change the size of the program window, the JTextAreas, and their respective texts appear on the screen.

How can I correct this so that the program loads, with the text areas populated, without the need to mess with the window? My apologies in advance for being a Swing noob.

My guess: You need to call setVisible(true) on the JFrame after adding all components to it.

Next time, or this time if this doesn't answer your question, please post pertinent code. We're terrible at reading minds or guessing at code not shown. Please check out the Jon Skeet blog: Asking the Perfect Question . It will give you great suggestions on how to create better more complete questions and thus get better answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM