SlideShare ist ein Scribd-Unternehmen logo
1 von 17
LAYOUT MANAGER
Chapter 11.3:
Layout Managers
 The layout manager determines how the GUI
components are added to the container (such as
the content pane of a frame)
 Layout managers are set in containers using the
setLayout(LayoutManager) method in a container
FlowLayout
 In using this layout, GUI components
are placed in left-to-right order.
 When the component does not fit on the
same line, left-to-right placement continues
on the next line.
 As a default, components on each line
are centered.
 When the frame containing the
component is resized, the placement of
components is adjusted accordingly.
FlowLayout Sample
This shows
the placement
of five buttons
by using
FlowLayout.
FlowLayout
 The components are arranged
in the container from left to
right in the order in which they
were added.
 When one row becomes filled,
a new row is started.
 FlowLayout can be aligned in 3
ways:
FlowLayout.LEFT – left aligned
FlowLayout.RIGHT – right aligned
FlowLayout.CENTER – center aligned
FlowLayout Constructors
 public FlowLayout(int align, int hGap,
int vGap)
Constructs a new FlowLayout with a specified alignment,
horizontal gap, and vertical gap. The gaps are the distances in
pixel between components.
 public FlowLayout(int alignment)
Constructs a new FlowLayout with a specified alignment and a
default gap of five pixels for both horizontal and vertical.
 public FlowLayout()
Constructs a new FlowLayout with a default center alignment
and a default gap of five pixels for both horizontal and vertical.
import java.awt.*;
import javax.swing.*;
//import java.awt.event.*;
public class TestFlowLayout extends JFrame
{
public TestFlowLayout()
{
super(“Using flowLayout");
Container cpane = getContentPane();
cpane.setLayout(new FlowLayout(FlowLayout.LEFT,20,10));
for (int i=1; i<7;i++)
cpane.add(new JButton("button "+i));
setSize(300,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestFlowLayout teks = new TestFlowLayout();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
10
20
BorderLayout
 This layout manager divides the container into five
regions: center, north, south, east, and west.
 The north and south regions expand or shrink in
width only
 The east and west regions expand or shrink in
height only
 The center region expands or shrinks on both
height and width.
 Not all regions have to be occupied.
BorderLayout Sample
GridLayout
 This layout manager placesGUI components on
equal-size N by M grids.
 Components are placed in top-to-bottom, left-to-
right order.
 The number of rows and columns remains the
same after the frame is resized, but the width and
height of each region will change.
GridLayout Sample
Using Panels as Containers
 Panels act as smaller containers for grouping user
interface components.
 It is recommended that you place the user
interface components in panels and place the
panels in a frame. You can also place panels in a
panel.
 To add a component to JFrame, you actually add it
to the content pane of JFrame. To add a
component to a panel, you add it directly to the
panel using the add method.
Create a JPanel
example :
Container cpane = getContentPane();
JPanel pan = new JPanel(); // create a panel
pan.add(new JButton(“Click”)); // add a button in the panel
cpane.add(pan) // add the panel in the container
label TextField
Text Area
button button
There are 3 panels :
top panel – has 2 components that are label, textfield
- 2 components are arranged with flowLayout
middle panel – has a component: text area. It is arranged with Gridlayout
bottom panel – has 2 components that are buttons
- 2components are arranged with Flowlayout
All panels are arrranged with borderlayout
top panel –north middle panel –center bottom panel –South
Top
panel
Middle
panel
Bottom
panel
import java.awt.*;
import javax.swing.*;
public class UjiPanel extends JFrame
{
public UjiPanel()
{
super("Membuat BorderLayout");
Container bekas = getContentPane();
bekas.setLayout(new BorderLayout());
JPanel panelAtas = new JPanel();
bekas.add(panelAtas,BorderLayout.NORTH);
JLabel label = new JLabel("Nama");
JTextField txtField = new JTextField(10);
panelAtas.setLayout(new FlowLayout());
panelAtas.add(label);
panelAtas.add(txtField);
JPanel panelTengah = new JPanel();
bekas.add(panelTengah,BorderLayout.CENTER);
JTextArea txtArea = new JTextArea();
panelTengah.setLayout(new GridLayout());
panelTengah.add(txtArea);
JPanel panelBawah = new JPanel();
bekas.add(panelBawah,BorderLayout.SOUTH);
JButton btg1 = new JButton("Hantar");
JButton btg2 = new JButton("Batal");
btg2.setMnemonic('B');
panelBawah.setLayout(new FlowLayout());
panelBawah.add(btg1);
panelBawah.add(btg2);
setSize(300,200);
setVisible(true);
} // konstruktor
public static void main(String[] arg)
{
UjiPanel teks = new UjiPanel();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Step in Creating Panel
 Set a layout manager for a container (frame).
 Create a panel
 Set a layout for the panel.
 Add the panel in the container (frame)
 Create a component that to be added in the panel
 Add the component in the panel

Weitere ähnliche Inhalte

Andere mochten auch

Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3
sotlsoc
 
Chapter 6.3
Chapter 6.3Chapter 6.3
Chapter 6.3
sotlsoc
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
sotlsoc
 
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제 정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
MJeNews
 
Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2
sotlsoc
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
sotlsoc
 
Presentacion leydi perezI
Presentacion leydi perezIPresentacion leydi perezI
Presentacion leydi perezI
leydip2009
 
Dangers to social media
Dangers to social mediaDangers to social media
Dangers to social media
Ryan Ward
 
Java programming-Event Handling
Java programming-Event HandlingJava programming-Event Handling
Java programming-Event Handling
Java Programming
 
8layout Managers
8layout Managers8layout Managers
8layout Managers
Adil Jafri
 

Andere mochten auch (16)

Chapter 4.3
Chapter 4.3Chapter 4.3
Chapter 4.3
 
Chapter 6.3
Chapter 6.3Chapter 6.3
Chapter 6.3
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제 정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
정몽준 서울시장 새누리당 후보 정책 공약 _ 33한서울88한경제
 
Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Cyberbullying by alex pitcher
Cyberbullying by alex pitcherCyberbullying by alex pitcher
Cyberbullying by alex pitcher
 
Presentacion leydi perezI
Presentacion leydi perezIPresentacion leydi perezI
Presentacion leydi perezI
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
 
Dangers to social media
Dangers to social mediaDangers to social media
Dangers to social media
 
Java
JavaJava
Java
 
Smart phone. addiction. blindness
Smart phone. addiction. blindnessSmart phone. addiction. blindness
Smart phone. addiction. blindness
 
Java programming-Event Handling
Java programming-Event HandlingJava programming-Event Handling
Java programming-Event Handling
 
Awt
AwtAwt
Awt
 
8layout Managers
8layout Managers8layout Managers
8layout Managers
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 

Ähnlich wie Chapter 11.3

Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1
Muhammad Shebl Farag
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 

Ähnlich wie Chapter 11.3 (20)

java swing
java swingjava swing
java swing
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
Chap1 1 4
Chap1 1 4Chap1 1 4
Chap1 1 4
 
AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Java GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdfJava GUI Programming for beginners-graphics.pdf
Java GUI Programming for beginners-graphics.pdf
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
28 awt
28 awt28 awt
28 awt
 
swingbasics
swingbasicsswingbasics
swingbasics
 
Java swing
Java swingJava swing
Java swing
 
Oop lecture9 10
Oop lecture9 10Oop lecture9 10
Oop lecture9 10
 
Swing jecrc
Swing jecrc Swing jecrc
Swing jecrc
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
258lec11
258lec11258lec11
258lec11
 
ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
 

Mehr von sotlsoc

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
sotlsoc
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
sotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
sotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
sotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
sotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
sotlsoc
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
sotlsoc
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2
sotlsoc
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
sotlsoc
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2
sotlsoc
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2
sotlsoc
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
sotlsoc
 

Mehr von sotlsoc (20)

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 
Chapter 9.2
Chapter 9.2Chapter 9.2
Chapter 9.2
 
Chapter 8.3
Chapter 8.3Chapter 8.3
Chapter 8.3
 
Chapter 8.2
Chapter 8.2Chapter 8.2
Chapter 8.2
 
Chapter 5.2
Chapter 5.2Chapter 5.2
Chapter 5.2
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Chapter 11.3

  • 2. Layout Managers  The layout manager determines how the GUI components are added to the container (such as the content pane of a frame)  Layout managers are set in containers using the setLayout(LayoutManager) method in a container
  • 3. FlowLayout  In using this layout, GUI components are placed in left-to-right order.  When the component does not fit on the same line, left-to-right placement continues on the next line.  As a default, components on each line are centered.  When the frame containing the component is resized, the placement of components is adjusted accordingly.
  • 4. FlowLayout Sample This shows the placement of five buttons by using FlowLayout.
  • 5. FlowLayout  The components are arranged in the container from left to right in the order in which they were added.  When one row becomes filled, a new row is started.  FlowLayout can be aligned in 3 ways: FlowLayout.LEFT – left aligned FlowLayout.RIGHT – right aligned FlowLayout.CENTER – center aligned
  • 6. FlowLayout Constructors  public FlowLayout(int align, int hGap, int vGap) Constructs a new FlowLayout with a specified alignment, horizontal gap, and vertical gap. The gaps are the distances in pixel between components.  public FlowLayout(int alignment) Constructs a new FlowLayout with a specified alignment and a default gap of five pixels for both horizontal and vertical.  public FlowLayout() Constructs a new FlowLayout with a default center alignment and a default gap of five pixels for both horizontal and vertical.
  • 7. import java.awt.*; import javax.swing.*; //import java.awt.event.*; public class TestFlowLayout extends JFrame { public TestFlowLayout() { super(“Using flowLayout"); Container cpane = getContentPane(); cpane.setLayout(new FlowLayout(FlowLayout.LEFT,20,10)); for (int i=1; i<7;i++) cpane.add(new JButton("button "+i)); setSize(300,200); setVisible(true); } public static void main(String[] arg) { TestFlowLayout teks = new TestFlowLayout(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } 10 20
  • 8. BorderLayout  This layout manager divides the container into five regions: center, north, south, east, and west.  The north and south regions expand or shrink in width only  The east and west regions expand or shrink in height only  The center region expands or shrinks on both height and width.  Not all regions have to be occupied.
  • 10. GridLayout  This layout manager placesGUI components on equal-size N by M grids.  Components are placed in top-to-bottom, left-to- right order.  The number of rows and columns remains the same after the frame is resized, but the width and height of each region will change.
  • 12. Using Panels as Containers  Panels act as smaller containers for grouping user interface components.  It is recommended that you place the user interface components in panels and place the panels in a frame. You can also place panels in a panel.  To add a component to JFrame, you actually add it to the content pane of JFrame. To add a component to a panel, you add it directly to the panel using the add method.
  • 13. Create a JPanel example : Container cpane = getContentPane(); JPanel pan = new JPanel(); // create a panel pan.add(new JButton(“Click”)); // add a button in the panel cpane.add(pan) // add the panel in the container
  • 14. label TextField Text Area button button There are 3 panels : top panel – has 2 components that are label, textfield - 2 components are arranged with flowLayout middle panel – has a component: text area. It is arranged with Gridlayout bottom panel – has 2 components that are buttons - 2components are arranged with Flowlayout All panels are arrranged with borderlayout top panel –north middle panel –center bottom panel –South Top panel Middle panel Bottom panel
  • 15. import java.awt.*; import javax.swing.*; public class UjiPanel extends JFrame { public UjiPanel() { super("Membuat BorderLayout"); Container bekas = getContentPane(); bekas.setLayout(new BorderLayout()); JPanel panelAtas = new JPanel(); bekas.add(panelAtas,BorderLayout.NORTH); JLabel label = new JLabel("Nama"); JTextField txtField = new JTextField(10); panelAtas.setLayout(new FlowLayout()); panelAtas.add(label); panelAtas.add(txtField); JPanel panelTengah = new JPanel(); bekas.add(panelTengah,BorderLayout.CENTER); JTextArea txtArea = new JTextArea(); panelTengah.setLayout(new GridLayout()); panelTengah.add(txtArea); JPanel panelBawah = new JPanel(); bekas.add(panelBawah,BorderLayout.SOUTH); JButton btg1 = new JButton("Hantar"); JButton btg2 = new JButton("Batal"); btg2.setMnemonic('B'); panelBawah.setLayout(new FlowLayout()); panelBawah.add(btg1); panelBawah.add(btg2);
  • 16. setSize(300,200); setVisible(true); } // konstruktor public static void main(String[] arg) { UjiPanel teks = new UjiPanel(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 17. Step in Creating Panel  Set a layout manager for a container (frame).  Create a panel  Set a layout for the panel.  Add the panel in the container (frame)  Create a component that to be added in the panel  Add the component in the panel