本文介绍了部件和轻量化/重量级之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是轻量级,重量级的JPanel并JFrame的关系和区别?

What is the difference between JPanel and JFrame and relationship to lightweight, heavyweight?

推荐答案

的JPanel是容器,它允许把几个UI组件在一起。 JFrame的是使用Swing编写的一个窗口。

JPanel is container that allows to put several UI components together. JFrame is a window written using Swing.

因为他们是用Java编写所有的Swing组件是所谓的lightwight组件。例如,如果你运行的Swing应用程序并尝试使用UI分析工具(例如WinSpy在Windows中)来分析它,你看到的只是一个元素:窗口(JFrame的)本身。所有其它组分但从操作系统点绘制。

All Swing components are so-called "lightwight" components because they are written in java. If for example you run Swing application and try to analyze it using UI analyzing tool (e.g. WinSpy in windows) you see only one element: the window (JFrame) itself. All other components are drawn from OS point of view.

重量级的API - AWT使用由操作系统提供便携元素。由于Java必须在各种操作系统AWT移植是非常有限的。它仅实现所有平台都支持屏幕元素的最小子集。然而,AWT元素直接映射到相应的平台元素,使UI发现工具会看到他们。这些元素被命名为重量级。

Heavyweight API - AWT uses portable elements provided by OS. Since java must be portable among various operating system AWT is very limited. It implements only the minimal subset of screen elements supported by all platforms. However the AWT elements are mapped directly to the appropriate platform elements, so UI discovery tool will see them. These elements are named "heavy weight".

这篇关于部件和轻量化/重量级之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:36