Java Swing:JPanel仅在JFrame窗口最大化或更改大小时添加组件 [英] Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

查看:250
本文介绍了Java Swing:JPanel仅在JFrame窗口最大化或更改大小时添加组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java程序,可以创建JFrame,JPanel和几个JTextAreas。我设置了JTextAreas的文本,然后将它们添加到JPanel。程序加载时,我只看到空的JFrame。

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.

但是,如果我最大化或更改程序窗口的大小,JTextAreas及其各自的文本将显示在屏幕上。

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

我如何纠正这个问题,以便程序加载,填充文本区域,而不需要弄乱窗口?我提前道歉作为Swing noob。

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.

推荐答案

我的猜测:你需要调用 setVisible(在 之后添加所有组件的

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

下次,或者这次如果没有回答您的问题,请发布相关代码。我们在阅读思想或猜测未显示的代码时非常糟糕。请查看Jon Skeet博客:要求完美的问题。它将为您提供有关如何创建更完整的问题的更好建议,从而获得更好的答案。

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.

这篇关于Java Swing:JPanel仅在JFrame窗口最大化或更改大小时添加组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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