Panel in a Panel in a Panel

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Yes.

Panel in a Panel in a Panel

[Morning Noon and Night]

The three panels that hold the label/text field pairs are added to yet another panel (called dataPanel in the code) using Boxlayout with vertical alignment. The buttons are added to their own panel. Then the dataPanel and the button panel are added to the frame. The picture shows how this works.

This idea of nesting panels is a powerful one. It may look complicated and tedious, but it is much less so than laying out a design on graph paper and specifying the exact size and location of all the components. Such a design has no flexibility. What happens if you want to add or delete a component? Everything must change. With Java's layout managers everything is dynamically adjusted.

QUESTION 16:

(Thought Question: ) Do you imagine that Java has a way that allows the programmer to exactly specify the size and location of components?