SlideShare a Scribd company logo
1 of 24
GRAPHICAL USERGRAPHICAL USER
INTERFACEINTERFACE
1.4 USE LAYOUT1.4 USE LAYOUT
MANAGERMANAGER
Learning Outcomes
 By the end of the class, student should be
able to:
 Define the use of layout manager in AWT
 Use layout manager in AWT:
 FlowLayout
 GridLayout
 BorderLayout
 BoxLayout
 Write java program using layout manager
USE OF LAYOUT
MANAGERS
 The UI components are placed in
containers.
 Each container has a layout manager to
arrange the GUI components within
the container.
LAYOUT MANAGERS
 FlowLayout
 GridLayout
 BorderLayout
 BoxLayout
SYNTAXTO SET LAYOUT
MANAGER
container.setLayout(new
SpecificLayout());
container.setLayout(new
SpecificLayout());
setLayout(new SpecificLayout());setLayout(new SpecificLayout());
Set the layout manager
here
Set the layout manager
here
AWT
SWING
FlowLayout
 Simplest and most basic layout manager
 Components arranged in container from left to
right in the order in which they were added
 When edge of container reached, continues
on next line
 Can determine the gap between components
in pixels.
 Three constant (alignment):
 FlowLayout.RIGHT
 FlowLayout.LEFT
 FlowLayout.CENTER
FlowLayout.CENTER
FlowLayout.RIGHT
FlowLayout.LEFT
FlowLayout CONSTRUCTOR
 public FlowLayout(int align, int hGap,
int vGap)
Constructs a new FlowLayout with a specified alignment,
horizontal gap and vertical gap. The g aps are the distances
in
pixel between components.
 public FlowLayout(int alignment)
Constructs a new FlowLayout with a specified alignment
and a default gap of 5 pixels for both horizontal and vertical.
 public FlowLayout()
Constructs a new FlowLayout with a default center
alignment and a default gap of 5 pixels for both horizontal
and vertical.
import java.awt.*;
import javax.swing.*;
public class TestFlowLayout extends JFrame
{
public TestFlowLayout()
{
super(“Create FlowLayout");
Container c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT,20,10));
for (int i=1; i<9;i++)
c.add(new Button("button "+i));
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestFlowLayout s = new TestFlowLayout();
s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
10
20
GridLayout
 Divides container into a grid
 Components placed in rows and columns
 All components have same width and height
 Added starting from top left, then from left to right
 When row full, continues on next row, left to right
GridLayout CONSTRUCTOR
 public GridLayout()
Construct a new GridLayout with one column
in a single row.
 public GridLayout(int rows,
int columns)
Constructs a new GridLayout with the
specified number of rows and columns.
GridLayout CONSTRUCTOR
 public GridLayout(int rows, int
columns, int hGap, int vGap)
Constructs a new GridLayout with the
specified number of rows and columns,
along with specified horizontal and vertical
gaps between components.
import java.awt.*;
import javax.swing.*;
public class TestGridLayout extends JFrame
{
public TestGridLayout()
{
super(“Create GridLayout");
Container s = getContentPane();
s.setLayout(new GridLayout(3,2,20,10));
for (int i=1; i<7;i++)
s.add(new Button("button "+i));
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestGridLayout t = new TestGridLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
BorderLayout
 Divides the window into 5 areas:
 BorderLayout.NORTH - North
 BorderLayout. SOUTH - South
 BorderLayout. EAST - East
 BorderLayout. WEST - West
 BorderLayout. CENTER - Center
BorderLayout CONSTRUCTOR
 public BorderLayout()
Construct a new BorderLayout without
horizontal or vertical gaps
 public BorderLayout(int hGap,
int vGap)
Constructs a new BorderLayout with the
specified horizontal and vertical gaps
between the components.
import java.awt.*;
import javax.swing.*;
public class TestBorderLayout extends JFrame
{
public TestBorderLayout()
{
super(“Create BorderLayout");
Container s = getContentPane();
s.setLayout(new BorderLayout(20,10));
Button bNorth = new Button(“North");
Button bSouth = new Button(“South");
Button bEast = new Button(“East");
Button bWest = new Button(“West");
Button bCenter = new Button(“Center");
s.add(bNorth,BorderLayout.NORTH);
s.add(bSouth,BorderLayout.SOUTH);
s.add(bEast,BorderLayout.EAST);
s.add(bWest,BorderLayout.WEST);
s.add(bCenter,BorderLayout.CENTER);
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestBorderLayout t = new TestBorderLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
public class TestBorderLayout extends JFrame
{
public TestBorderLayout()
{
super(“Create BorderLayout");
Container s = getContentPane();
s.setLayout(new BorderLayout(20,10));
Button bNorth = new Button(“North");
Button bSouth = new Button(“South");
Button bEast = new Button(“East");
Button bWest = new Button(“West");
Button bCenter = new Button(“Center");
//s.add(bNorth,BorderLayout.NORTH);
s.add(bSouth,BorderLayout.SOUTH);
s.add(bEast,BorderLayout.EAST);
s.add(bWest,BorderLayout.WEST);
s.add(bCenter,BorderLayout.CENTER);
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestBorderLayout t = new TestBorderLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
public class TestBorderLayout extends JFrame
{
public TestBorderLayout()
{
super(“Create BorderLayout");
Container s = getContentPane();
s.setLayout(new BorderLayout(20,10));
Button bNorth = new Button(“North");
Button bSouth = new Button(“South");
Button bEast = new Button(“East");
Button bWest = new Button(“West");
Button bCenter = new Button(“Center");
s.add(bNorth,BorderLayout.NORTH);
s.add(bSouth,BorderLayout.SOUTH);
//s.add(bEast,BorderLayout.EAST);
s.add(bWest,BorderLayout.WEST);
s.add(bCenter,BorderLayout.CENTER);
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestBorderLayout t = new TestBorderLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
public class TestBorderLayout extends JFrame
{
public TestBorderLayout()
{
super(“Create BorderLayout");
Container s = getContentPane();
s.setLayout(new BorderLayout(20,10));
Button bNorth = new Button(“North");
Button bSouth = new Button(“South");
Button bEast = new Button(“East");
Button bWest = new Button(“West");
Button bCenter = new Button(“Center");
//s.add(bNorth,BorderLayout.NORTH);
s.add(bSouth,BorderLayout.SOUTH);
//s.add(bEast,BorderLayout.EAST);
//s.add(bWest,BorderLayout.WEST);
s.add(bCenter,BorderLayout.CENTER);
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestBorderLayout t = new TestBorderLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
public class TestBorderLayout extends JFrame
{
public TestBorderLayout()
{
super(“Create BorderLayout");
Container s = getContentPane();
s.setLayout(new BorderLayout(20,10));
Button bNorth = new Button(“North");
Button bSouth = new Button(“South");
Button bEast = new Button(“East");
Button bWest = new Button(“West");
Button bCenter = new Button(“Center");
s.add(bNorth,BorderLayout.NORTH);
s.add(bSouth,BorderLayout.SOUTH);
s.add(bEast,BorderLayout.EAST);
s.add(bWest,BorderLayout.WEST);
//s.add(bCenter,BorderLayout.CENTER);
setSize(350,200);
setVisible(true);
}
public static void main(String[] arg)
{
TestBorderLayout t = new TestBorderLayout();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
BoxLayout
 A layout manager that allows multiple
components to be laid out either vertically
or horizontally.
 The value of axis can be one of the
following:
 BoxLayout.X_AXIS
 BoxLayout.Y_AXIS
 BoxLayout.LINE_AXIS
 BoxLayout.PAGE_AXIS
 BoxLayout has a single constructor:
public Bo xLayo ut(Co ntaine r targ e t, int axis)
 public BoxLayout(Container target, int axis)
 The first argument is the container
 The second is the layout direction.
Summary
 4 layout manager: FlowLayout, BorderLayout,
GridLayout and BoxLayout.

More Related Content

What's hot

Austin Bingham. Transducers in Python. PyCon Belarus
Austin Bingham. Transducers in Python. PyCon BelarusAustin Bingham. Transducers in Python. PyCon Belarus
Austin Bingham. Transducers in Python. PyCon BelarusAlina Dolgikh
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONAndrea Antonello
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTAndrea Antonello
 
Designing Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberDesigning Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberJorge Lainfiesta
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your networkPushpendra Tiwari
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices pythonUtkarsh Asthana
 

What's hot (9)

Austin Bingham. Transducers in Python. PyCon Belarus
Austin Bingham. Transducers in Python. PyCon BelarusAustin Bingham. Transducers in Python. PyCon Belarus
Austin Bingham. Transducers in Python. PyCon Belarus
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHON
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORT
 
Chapter 6 arrays part-1
Chapter 6   arrays part-1Chapter 6   arrays part-1
Chapter 6 arrays part-1
 
Queue
QueueQueue
Queue
 
Designing Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberDesigning Immutability Data Flows in Ember
Designing Immutability Data Flows in Ember
 
IGraph a tool to analyze your network
IGraph a tool to analyze your networkIGraph a tool to analyze your network
IGraph a tool to analyze your network
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices python
 

Viewers also liked

Fp601 chapter 3 - part 2
Fp601   chapter 3 - part 2Fp601   chapter 3 - part 2
Fp601 chapter 3 - part 2Hemo Chella
 
Fp601 chapter 3 - part 1
Fp601   chapter 3 - part 1Fp601   chapter 3 - part 1
Fp601 chapter 3 - part 1Hemo Chella
 
Introduction to financial planning
Introduction to financial planningIntroduction to financial planning
Introduction to financial planningJohn Daniel
 
INTRODUCTION TO FINANCIAL PLANNING
INTRODUCTION TO FINANCIAL PLANNINGINTRODUCTION TO FINANCIAL PLANNING
INTRODUCTION TO FINANCIAL PLANNINGDIANN MOORMAN
 
Basic Financial Planning Concepts
Basic Financial Planning ConceptsBasic Financial Planning Concepts
Basic Financial Planning ConceptsMohd Hijazi
 

Viewers also liked (9)

Fp601 chapter 3 - part 2
Fp601   chapter 3 - part 2Fp601   chapter 3 - part 2
Fp601 chapter 3 - part 2
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
 
Fp601 chapter 2
Fp601   chapter 2Fp601   chapter 2
Fp601 chapter 2
 
Ent300 module06
Ent300 module06Ent300 module06
Ent300 module06
 
cyberpreneurship
cyberpreneurshipcyberpreneurship
cyberpreneurship
 
Fp601 chapter 3 - part 1
Fp601   chapter 3 - part 1Fp601   chapter 3 - part 1
Fp601 chapter 3 - part 1
 
Introduction to financial planning
Introduction to financial planningIntroduction to financial planning
Introduction to financial planning
 
INTRODUCTION TO FINANCIAL PLANNING
INTRODUCTION TO FINANCIAL PLANNINGINTRODUCTION TO FINANCIAL PLANNING
INTRODUCTION TO FINANCIAL PLANNING
 
Basic Financial Planning Concepts
Basic Financial Planning ConceptsBasic Financial Planning Concepts
Basic Financial Planning Concepts
 

Similar to Chap1 1 4

3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsbabhishekmathuroffici
 
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_1Muhammad Shebl Farag
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART IIOXUS 20
 
Value isnt changing and I cant seem to get the conversion to wor.pdf
Value isnt changing and I cant seem to get the conversion to wor.pdfValue isnt changing and I cant seem to get the conversion to wor.pdf
Value isnt changing and I cant seem to get the conversion to wor.pdfamirthagiftsmadurai
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu isRakesh Madugula
 
ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME RRamyaDevi
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfMarlouFelixIIICunana
 
Advanced Java programming
Advanced Java programmingAdvanced Java programming
Advanced Java programmingvanmathy1
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3sotlsoc
 
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 AWTDrRajeshreeKhande
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 

Similar to Chap1 1 4 (20)

3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
LAYOUT.pptx
LAYOUT.pptxLAYOUT.pptx
LAYOUT.pptx
 
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
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
Value isnt changing and I cant seem to get the conversion to wor.pdf
Value isnt changing and I cant seem to get the conversion to wor.pdfValue isnt changing and I cant seem to get the conversion to wor.pdf
Value isnt changing and I cant seem to get the conversion to wor.pdf
 
swingbasics
swingbasicsswingbasics
swingbasics
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu is
 
java swing
java swingjava swing
java swing
 
Java swing
Java swingJava swing
Java swing
 
ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME ADVANCED JAVA PROGRAMME
ADVANCED JAVA PROGRAMME
 
Layout manager
Layout managerLayout manager
Layout manager
 
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdfJEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
JEDI Slides-Intro2-Chapter19-Abstract Windowing Toolkit and Swing.pdf
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
Advanced Java programming
Advanced Java programmingAdvanced Java programming
Advanced Java programming
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
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
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
Swing
SwingSwing
Swing
 
28 awt
28 awt28 awt
28 awt
 

More from Hemo Chella

More from Hemo Chella (10)

Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
Chap2 2 1
Chap2 2 1Chap2 2 1
Chap2 2 1
 
Chap1 1 1
Chap1 1 1Chap1 1 1
Chap1 1 1
 
Chap1 1.1
Chap1 1.1Chap1 1.1
Chap1 1.1
 
Fp601 chapter 6
Fp601   chapter 6Fp601   chapter 6
Fp601 chapter 6
 
Fp601 chapter 5 -part 1
Fp601   chapter 5 -part 1Fp601   chapter 5 -part 1
Fp601 chapter 5 -part 1
 
Fp601 chapter 5 - part 2
Fp601   chapter 5 - part 2Fp601   chapter 5 - part 2
Fp601 chapter 5 - part 2
 
Fp601 chapter 4
Fp601   chapter 4Fp601   chapter 4
Fp601 chapter 4
 
Fp601 chapter 1
Fp601   chapter 1Fp601   chapter 1
Fp601 chapter 1
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 

Chap1 1 4

  • 1. GRAPHICAL USERGRAPHICAL USER INTERFACEINTERFACE 1.4 USE LAYOUT1.4 USE LAYOUT MANAGERMANAGER
  • 2. Learning Outcomes  By the end of the class, student should be able to:  Define the use of layout manager in AWT  Use layout manager in AWT:  FlowLayout  GridLayout  BorderLayout  BoxLayout  Write java program using layout manager
  • 3. USE OF LAYOUT MANAGERS  The UI components are placed in containers.  Each container has a layout manager to arrange the GUI components within the container.
  • 4. LAYOUT MANAGERS  FlowLayout  GridLayout  BorderLayout  BoxLayout
  • 5. SYNTAXTO SET LAYOUT MANAGER container.setLayout(new SpecificLayout()); container.setLayout(new SpecificLayout()); setLayout(new SpecificLayout());setLayout(new SpecificLayout()); Set the layout manager here Set the layout manager here AWT SWING
  • 6. FlowLayout  Simplest and most basic layout manager  Components arranged in container from left to right in the order in which they were added  When edge of container reached, continues on next line  Can determine the gap between components in pixels.
  • 7.  Three constant (alignment):  FlowLayout.RIGHT  FlowLayout.LEFT  FlowLayout.CENTER
  • 9. FlowLayout CONSTRUCTOR  public FlowLayout(int align, int hGap, int vGap) Constructs a new FlowLayout with a specified alignment, horizontal gap and vertical gap. The g aps are the distances in pixel between components.  public FlowLayout(int alignment) Constructs a new FlowLayout with a specified alignment and a default gap of 5 pixels for both horizontal and vertical.  public FlowLayout() Constructs a new FlowLayout with a default center alignment and a default gap of 5 pixels for both horizontal and vertical.
  • 10. import java.awt.*; import javax.swing.*; public class TestFlowLayout extends JFrame { public TestFlowLayout() { super(“Create FlowLayout"); Container c = getContentPane(); c.setLayout(new FlowLayout(FlowLayout.LEFT,20,10)); for (int i=1; i<9;i++) c.add(new Button("button "+i)); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestFlowLayout s = new TestFlowLayout(); s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } 10 20
  • 11. GridLayout  Divides container into a grid  Components placed in rows and columns  All components have same width and height  Added starting from top left, then from left to right  When row full, continues on next row, left to right
  • 12. GridLayout CONSTRUCTOR  public GridLayout() Construct a new GridLayout with one column in a single row.  public GridLayout(int rows, int columns) Constructs a new GridLayout with the specified number of rows and columns.
  • 13. GridLayout CONSTRUCTOR  public GridLayout(int rows, int columns, int hGap, int vGap) Constructs a new GridLayout with the specified number of rows and columns, along with specified horizontal and vertical gaps between components.
  • 14. import java.awt.*; import javax.swing.*; public class TestGridLayout extends JFrame { public TestGridLayout() { super(“Create GridLayout"); Container s = getContentPane(); s.setLayout(new GridLayout(3,2,20,10)); for (int i=1; i<7;i++) s.add(new Button("button "+i)); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestGridLayout t = new TestGridLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 15. BorderLayout  Divides the window into 5 areas:  BorderLayout.NORTH - North  BorderLayout. SOUTH - South  BorderLayout. EAST - East  BorderLayout. WEST - West  BorderLayout. CENTER - Center
  • 16. BorderLayout CONSTRUCTOR  public BorderLayout() Construct a new BorderLayout without horizontal or vertical gaps  public BorderLayout(int hGap, int vGap) Constructs a new BorderLayout with the specified horizontal and vertical gaps between the components.
  • 17. import java.awt.*; import javax.swing.*; public class TestBorderLayout extends JFrame { public TestBorderLayout() { super(“Create BorderLayout"); Container s = getContentPane(); s.setLayout(new BorderLayout(20,10)); Button bNorth = new Button(“North"); Button bSouth = new Button(“South"); Button bEast = new Button(“East"); Button bWest = new Button(“West"); Button bCenter = new Button(“Center"); s.add(bNorth,BorderLayout.NORTH); s.add(bSouth,BorderLayout.SOUTH); s.add(bEast,BorderLayout.EAST); s.add(bWest,BorderLayout.WEST); s.add(bCenter,BorderLayout.CENTER); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestBorderLayout t = new TestBorderLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 18. import java.awt.*; import javax.swing.*; public class TestBorderLayout extends JFrame { public TestBorderLayout() { super(“Create BorderLayout"); Container s = getContentPane(); s.setLayout(new BorderLayout(20,10)); Button bNorth = new Button(“North"); Button bSouth = new Button(“South"); Button bEast = new Button(“East"); Button bWest = new Button(“West"); Button bCenter = new Button(“Center"); //s.add(bNorth,BorderLayout.NORTH); s.add(bSouth,BorderLayout.SOUTH); s.add(bEast,BorderLayout.EAST); s.add(bWest,BorderLayout.WEST); s.add(bCenter,BorderLayout.CENTER); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestBorderLayout t = new TestBorderLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 19. import java.awt.*; import javax.swing.*; public class TestBorderLayout extends JFrame { public TestBorderLayout() { super(“Create BorderLayout"); Container s = getContentPane(); s.setLayout(new BorderLayout(20,10)); Button bNorth = new Button(“North"); Button bSouth = new Button(“South"); Button bEast = new Button(“East"); Button bWest = new Button(“West"); Button bCenter = new Button(“Center"); s.add(bNorth,BorderLayout.NORTH); s.add(bSouth,BorderLayout.SOUTH); //s.add(bEast,BorderLayout.EAST); s.add(bWest,BorderLayout.WEST); s.add(bCenter,BorderLayout.CENTER); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestBorderLayout t = new TestBorderLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 20. import java.awt.*; import javax.swing.*; public class TestBorderLayout extends JFrame { public TestBorderLayout() { super(“Create BorderLayout"); Container s = getContentPane(); s.setLayout(new BorderLayout(20,10)); Button bNorth = new Button(“North"); Button bSouth = new Button(“South"); Button bEast = new Button(“East"); Button bWest = new Button(“West"); Button bCenter = new Button(“Center"); //s.add(bNorth,BorderLayout.NORTH); s.add(bSouth,BorderLayout.SOUTH); //s.add(bEast,BorderLayout.EAST); //s.add(bWest,BorderLayout.WEST); s.add(bCenter,BorderLayout.CENTER); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestBorderLayout t = new TestBorderLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 21. import java.awt.*; import javax.swing.*; public class TestBorderLayout extends JFrame { public TestBorderLayout() { super(“Create BorderLayout"); Container s = getContentPane(); s.setLayout(new BorderLayout(20,10)); Button bNorth = new Button(“North"); Button bSouth = new Button(“South"); Button bEast = new Button(“East"); Button bWest = new Button(“West"); Button bCenter = new Button(“Center"); s.add(bNorth,BorderLayout.NORTH); s.add(bSouth,BorderLayout.SOUTH); s.add(bEast,BorderLayout.EAST); s.add(bWest,BorderLayout.WEST); //s.add(bCenter,BorderLayout.CENTER); setSize(350,200); setVisible(true); } public static void main(String[] arg) { TestBorderLayout t = new TestBorderLayout(); t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 22. BoxLayout  A layout manager that allows multiple components to be laid out either vertically or horizontally.  The value of axis can be one of the following:  BoxLayout.X_AXIS  BoxLayout.Y_AXIS  BoxLayout.LINE_AXIS  BoxLayout.PAGE_AXIS
  • 23.  BoxLayout has a single constructor: public Bo xLayo ut(Co ntaine r targ e t, int axis)  public BoxLayout(Container target, int axis)  The first argument is the container  The second is the layout direction.
  • 24. Summary  4 layout manager: FlowLayout, BorderLayout, GridLayout and BoxLayout.