You are here

JFrame with JButtons but no event handlers (

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at
Note: is available in the source code archive file.

To display other GUI components on a JFrame, we first need to get the content pane of the JFrame and then add the desired GUI components to this content pane.

If we want to arrange the added GUI components in certain ways, we need to add an appropriate "layout manager" to the JFrame. The task of laying out the GUI component inside of a container GUI component is specifed by an interface called LayoutManager. In Frame1, we add the FlowLayout that arranges all GUI components in a linear fashion. If we do not add any layout manager to the JFrame, it has no layout manager and does a very bad job of arranging GUI components inside of it. As an exercise, comment out the code to add the FlowLayout to Frame1 and see what happens!