1

I found this line on the java docs tutorial site- "A Frame is a top-level window with a title and a border". Here, what is the meaning of "top-level window"?

4 Answers4

3

A 'top-level window' or 'top level container' is something that can be shown on screen without having to add it to another component. We would start a GUI with a top level container, and then add panels and components to that TLC. E.G. of top level containers..

See also this answer for many good reasons to abandon AWT components in favor of Swing. As to abandoning Swing for Java-FX, I'll be unwilling to do so until Java-FX is promoted to the Java API's Java docs, and makes it into the official Java Tutorial. Sun, then Oracle, has a bad habit of hyping many technologies only to later quietly drop support & development for them.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    The JavaFX equivalent would be `Stage` and `Window` (though it seems not all sub-classes are top-level windows). – Puce Mar 06 '17 at 21:26
1

In GUI toolkits such as AWT, a top-level window is a window which is usually known to the OS (heavy-weight components).

Side note: AWT (and even Swing) is a pretty old technology. I recommend to use JavaFX where possible.

Puce
  • 37,247
  • 13
  • 80
  • 152
  • what's your source for this definition. – Daij-Djan Mar 06 '17 at 13:24
  • @Daij-Djan I don't have a specific source of definition. But I just checked the official Java tutorial and Javadoc. They have a similar view: http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html – Puce Mar 06 '17 at 13:55
  • @Daij-Djan e.g. JInternalFrame (Swing) is not a top-level container. – Puce Mar 06 '17 at 13:57
-1

a window without a parent.

a window can have child windows alright and they have a parent then

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • e.g. Dialog (which often has a parent) is a top-level window as well – Puce Mar 06 '17 at 13:00
  • well it is different in all toolkits I know but Im willing to grant you the benefit of the doubt concerning java ;) – Daij-Djan Mar 06 '17 at 13:23
  • in my mind this definition is right still :) but it seems java seems to say 'only windows backed by separate native windows are top-level" – Daij-Djan Mar 06 '17 at 15:47
-1

Observe difference among these classes.

Frame is top level window because it has border and title. An instance of frame can have a menubar. Without those it is mere is an instance of java.awt.Window class.

Window class: It has neither border not title. Window class is not attached to nor embedded within another container.

Dialog: It has border and title. An instance of the Dialog class cannot exist without an associated instance of the Frame class.

Panel: just a generic container to hold components. Its instance provides a container to which to add components.

Note: Revert me back if further clarification is required.

Pratik Ambani
  • 2,523
  • 1
  • 18
  • 28