setResizable()

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. By default, JFrame objects can be resized.

setResizable()

One method for ensuring that a graphical interface looks the way you intend is to prevent the user from resizing it, using this method of JFrame:

public void setResizable(boolean resizable)

If the parameter is false then the user cannot resize the frame. But this does not solve all problems. When a frame contains several logical groups of components it may be difficult to lay them out correctly using a single layout manager. You would like to group related components together, and then to lay out the groups in the frame. This is where panels are useful.

QUESTION 2:

Could a label and the component it labels be put together in a panel?