views:

150

answers:

3

How does the JVM make it's windows, i know it has it's jar files and the executables, etc... what i would like to know is how exactly is a window made with java, the frame surrounding a desktop application.

is it a graphics library standard on the machines it is installed in?

+5  A: 

There are two types of UI components in Java: heavyweight and lightweight.

A heavyweight component is a wrapper for something that exists in the operating system. Windows as an operating system has methods to create windows, dialog boxes, etc.

A lightweight component is created entirely within the application using 2D drawing APIs and the like. The operating system knows nothing about it.

The two "official" Java GUI APIs are Swing and AWT. AWT is usually used by applets (early ones anyway). It consists of heavyweight components. Swing is built on top of AWT but is a far more extensive API for designing usually desktop applications. Most Swing components are lightweight.

So a Java desktop application may consist of one or more heavyweight components, probably with some lightweight components thrown in. Or it might be all lightweight components if the 2D drawing APIs are sufficient to "fake" Windows without a heavyweight component.

The frame you see around a Java application might be drawn their with a library like Java2D (either directly or via components that use that or a similar API) or it might be created by Windows with configuration from the application, probably affected by the operating system's theme and display settings.

Most Java applications these days are lightweight.

cletus
so as far as the heavyweight components go, it is basically an implementation of the built graphics library of the OS that the application is running on..and i looked up the lightweight components.. would it be true in me reading that, lightweight components are just painted onto the heavy weight component? this would explain the ability to over-ride the paintComponenet of different objects inside a java application.
Lonnie Ribordy
The top-level component of most (all?) Swing apps is a JFrame that extends the AWT Frame class, which is heavyweight OS Window. The rest are typically lightweight, so your description is right.
cletus
*All* Swing top-level components are heavy-weight - JFrames, JDialogs, etc. - there has to be something there for lightweight components to be drawn on.
Nate
A: 

By default frames, whether java.awt.Frame or javax.swing.JFrame (or equivalents) will be drawn by the underlying windowing system. Recently (2002), 1.4 introduced Frame.setUndecorated and related methods. This allows a frame to be drawn as an undecorated window (as Window does) and certain PL&F, such as Metal, can draw a functioning frame instead of delegating to the windowing system. This functionality was apparently implemented to allow a whole window to have the same look and feel. As far as I know, the Sun look and feel implementation that aim to duplicate native windowing system do not implement this feature.

Tom Hawtin - tackline
A: 

Just to be complete: there is also SWT which thin Java layer on top of native implementation of Windowing system. Sort of like AWT redone. It is used by Eclipse project. Should provide closer match to native L&F, faster rendering - but YMMV.

Disadvantage of SWT is that you have to learn additional API and the libraries must be available on all target platform. For example, until recently, OS-X version was rather incomplete and outdated (Carbon, not Cocoa based).

Miro A.