用JPanel添加组件是正确的事情 [英] adding component with out JPanel is it right thing

查看:97
本文介绍了用JPanel添加组件是正确的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有一个关于JPanel组件的问题,这是一个非常简单的问题,没有编码这个问题,如果我可以直接将它们直接添加到JFrame中,为什么我必须将gui组件添加到JPanel中,我总是必须添加所有组件给JPanel,如果我不这样做,那将在任何条件下影响该称谓

hello i had a question about JPanel component it is very simple question no coding the question why do i have to add gui component to the JPanel if i can simply adding them to the JFrame directly do i always have to add all the component to JPanel and if i did not do that is that going to effect the appellation in any term

推荐答案

您不必将内容添加到"JPanel"中,但是可以将它们直接添加到JFrame中,但是了解一些内容事情:

You don't have to add things to "the JPanel" but can add them directly to the JFrame, but understand a few things:

  • 使用add(...)方法将组件添加到典型的JFrame时,实际上是将其添加到JFrame的contentPane中.
  • ...这是 JPanel .
  • 如果执行此操作,则需要了解Java布局管理器,以及将组件添加到使用BorderLayout的容器中的含义,例如JFrame contentPanes.
  • 但是话虽如此,如果需要,您可以更改contentPane的布局管理器.
  • When you add components to a typical JFrame using the add(...) method, you're actually adding it to the JFrame's contentPane...
  • ... which is a JPanel.
  • If you do this, you will need to understand Java Layout Managers, and what it means to add a component to a containers that use BorderLayout, such as JFrame contentPanes do.
  • But having said that, you can change the layout manager of a contentPane if desired.

这篇关于用JPanel添加组件是正确的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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