Buttons 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. JButtons are components, and any component may be added to a JPanel.

Buttons in a Panel

Morning Noon and Night

 

Here is another example, now including buttons. Labels and text fields are grouped into small panels, as before. Those small panels are then grouped into three medium panels. The three buttons at the bottom are grouped together into a panel.

QUESTION 15:

(Thought Question: ) Can a JPanel that contains JPanels be added to another JPanel ? (Ie., can the nesting of JPanels go three levels deep?)