1 / 11

Layout Manager

Layout Manager. Layouts. Java has introduced a unique way of creating UI and displaying them on screen. Java has an interface called the LayoutManager which belongs to the java.awt package. A Layout manager determines how components will be arranged when they are added to a container(screen).

lysa
Download Presentation

Layout Manager

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Layout Manager

  2. Layouts • Java has introduced a unique way of creating UI and displaying them on screen. • Java has an interface called the LayoutManager which belongs to the java.awt package. • A Layout manager determines how components will be arranged when they are added to a container(screen).

  3. FlowLayout, BorderLayout,GridLayout and CardLayout are all classses which implement the LayoutManager interface. • To add a specific layout for a component an object of the above classes is created. • After creating a layout manager, the layout manager is made part of the container by using the setLayout() method of the Container class. • The layout manager must be established before any components are added to the container. • If no layout manager is specified, the container uses the Flow Layout manager by default.

  4. import java.awt.*; import java.applet.*; public class Starter extends Applet { FlowLayout flow = new FlowLayout(); public void init(){ setLayout(flow); } } Now components can be added to the container; in this case it is applet.

  5. Flow Layout • It lays out components in a manner similar to the way are laid out on a page, from left to right until there is no room, then onto the next row. • By default the components on each row centered by using FlowLayout(). • FlowLayout.RIGHT • FlowLayout.LEFT • FlowLayout.CENTER

  6. FlowLayout(int algn,int hrzGapPixel,int vrtGapPixel) • Example

  7. Grid Layout • Arranges components in grid of rows and columns. • Components are added first to the top of row of the grid, beginning with leftmost grid cell and continuing to the right. • GridLayout(int rows, int columns); • GridLayout(int rows,int col, int hrz_gap, int vrt_gap); • Example

  8. Border Layout • Divide a container into 5 location:north,south,east,west,center. • Components take as much space as they need, the center gets whatever space is left over. • BorderLayout() without gap between any of the component. • BorderLayout(int,int) specifies the gap. • add(String <loc>,component); • Example

  9. Card Layout • The card layout manager can be mixed with the other managers by nesting one container inside another. • It is a group of containers or components that are displayed one at a time. • Each container in the group is called a card.

  10. Card Layout is created by – CardLayout <obj> = new CardLayout(); setLayout(<obj>); add(String <name of card>, component); <obj>.show(container,cardName); Note: when using card layout the previously displyed card is hidden. Only one card layout can be viewed at a time

  11. Example • Example

More Related