Differences between components and lightweight/heavyweight

后端 未结 4 1404
野的像风
野的像风 2020-12-16 18:24

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

4条回答
  •  佛祖请我去吃肉
    2020-12-16 18:58

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

    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.

    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".

提交回复
热议问题