0% found this document useful (0 votes)
3 views15 pages

06 User Interface 2

The document outlines key concepts in Java Swing user interface design, focusing on content panes, color application, layout managers, JPanel, and JScrollPane. It provides learning objectives for students to understand and utilize these components effectively. Sample code snippets are included to illustrate the practical application of these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

06 User Interface 2

The document outlines key concepts in Java Swing user interface design, focusing on content panes, color application, layout managers, JPanel, and JScrollPane. It provides learning objectives for students to understand and utilize these components effectively. Sample code snippets are included to illustrate the practical application of these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Computer

Programming 2
Prepared By
Hazel Joy M. Alvarez
USER INTERFACE 2
Content Pane
Color
Layout Manager Classes
Jpanel
JScrollPane
Learning
Objectives
• At the end of the topic session, the
students should be able to:
• Use content panes
• Apply color to UI components
• Compare different layout managers
• Use the JPanel and JScrollPane classes
Content Pane
• The JFrame class is a top-level container class of Java Swing. Each GUI
component that appears on the screen should be part of a containment
hierarchy.
• A containment hierarchy is a tree of component that has a top-level
container as its root. Every top- level container has a content pane.
• A content pane is a layer that consists of all the visible components in
the user interface of a container. It can contain components or hold other
containers.
• The content pane of a JFrame can be referenced using the
getContentPane() method.
• Sample code that uses the JFrame’s content pane:
Output:
Color
• The Color class allows you to add colors to your applications to make
them more interactive and interesting. It can be used with
setBackground() and setForeground() methods of the Component
class for better user interface design.
• Named constants that represent colors which can be used:
BLACK ORANGE
BLUE PINK
CYAN RED
DARK_GRAY WHITE
GRAY YELLOW
LIGHT_GRAY
MAGENTA
• Sample code of a program that sets the background of a JFrame’s
content pane and sets both the foreground and background colors of a
JButton:
Layout Manager Classes
• List of Layout Managers:

Layout Description
Manager
Adds components to a maximum of five (5) sections arranged in
BorderLayout north, south, east, west, and center positions
Adds components into a grid of rows and columns
GridLayout Each component is the same size
BorderLayout

Output:
GridLayout

Output:
JPanel
• A JPanel is a plain, borderless surface that can hold lightweight UI
components.
• Constructors of the JPanel Class:
• JPanel() – creates a JPanel with double buffering and a FlowLayout.
• JPanel(LayoutManager layout) – creates a JPanel with the specified
layout manager and double buffering.
• JPanel(Boolean isDoubleBuffered) – creates a JPanel with a FlowLayout
and the specified double buffering strategy.
• JPanel(LayoutManager layout, Boolean isDoubleBuffered) – creates a
Jpanel with the specified layout manager and the specified double buffering
strategy.
JPanel
• Sample Code for Jpanel:
JScrollPane
• A JScrollPane provides scroll bars along the side or the bottom of a
pane, or both, with a viewable area called a viewport.
• Constructors of the JScrollPane Class:
• JScrollPane() – creates an empty JScrollPane in which both horizontal and
vertical scroll bars appear when needed.

• JScrollPane(Component) – creates a JScrollPane that displays the contents


of the specified component.
JScrollPane
• JScrollPane(int, int) – creates a JScrollPane with both vertical and horizontal
scroll bar specifications.

• JScrollPane(Component, int, int) – creates a JScrollPane that displays the


specified component and includes both vertical and horizontal bar
specifications.
Sample Code:

Output:

You might also like