Programming Java GUI Layout | JFrame Content Pane Layout | Java...

GUI Layout | JFrame Content Pane Layout | Java Graphics | CS School

-

Previously we discussed some basic intuition of Java graphical user interface, or GUI. In this article we will talk about some general idea of GUI Layout. By default, a JFrame has five regions we can add widgets or custom graphics. We are allowed to add only one thing to each region on the frame. But that one thing might be a panel that can hold three other things, including a panel that also can hold other two things .. an so on. Let see HOW?

GUI Layout | Content Pane Layout

Previously we also have talked about the simple way of adding widgets, such as button, checkbox, textarea, etc on  JFrame’s content pane.

frame.getContentPane().add(button);

But that is In-fact, not the right way of adding thing on the frame. Rather, we should take two arguments in add method, that takes a region (i. e.center, east, north, etc) and the widget to add to that region. Figure below, we have illustrated the default JFrame’s content pane layout:

GUI Layout | JFrame Content Pane Layout | Java Graphics | CS School
Figure: GUI Layout, or JFrame Content Pane Layout 

So, we can add things (such as buttons) on that layout in following manner:

frame.getContentPane().add(BorderLayout.CENTER, button);

This is usually the mandatory way to add things to JFrame’s default content pane. But when we don’t specify the region the widget will automatically land on the default center region of the content pane.

//This is just an introduction of JFrame’s content pane layout, or java gui Layout. Next we will talk about how to add different widgets to content pane-layout’s different regions. We will also discuss about how to register Listeners to different buttons on GUI Layout to handle different events that occur with user interaction. see here>>

Latest Articles

Property Decorator | Getters Setters and Deleters in Python

In this article, we will talk about the Property Decorator in Python. It enables the class functionality...

Dictionaries | HashMap in Python | Working with Key-Values

Dictionaries in Python is similar to Hashmap comparing to other languages. It stores data as a key-value...

Hash Table | Indexing | Hashing Algorithm | Python Implementation

This article will talk about a high-level view of the Hash Table. As a programmer, this technique...

Eigenvector Eigenvalue | Linear Algebra Fundamentals

Eigenvector ($bar{v}$) in linear algebra is a non-zero vector (matrix) that doesn't change its direction during linear...

Pivot Table | Microsoft Excel | Create Data Insight Easily

Pivot table in microsoft Excel is an useful function that gives us a way to create insight...

Macro Function in Microsoft Excel | Automate Repetitive Task

This article we will talk about the Macro. It is a function in microsoft excel which basically...

Must read

Dictionaries | HashMap in Python | Working with Key-Values

Dictionaries in Python is similar to Hashmap...

You might also likeRELATED
Recommended to you