Setting the Layout Manager

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.

Setting the Layout Manager

Here is how the layout manager was set for our JFrame:

import java.awt.*;
import javax.swing.*;
 
public class ButtonFrame  extends JFrame
{
  JButton bChange; 

  ButtonFrame(String title) 
  {
    super( title );                      
    setLayout( new FlowLayout() );      // set the layout manager

    bChange = new JButton("Click Me!");  
    add( bChange );                      
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
  }

}

The layout manager is set using the setLayout() method of the frame.

QUESTION 7:

If there is only one component to place in a content pane, where do you suppose FlowLayout puts it?