Sie sind auf Seite 1von 23

Session 3

Layout Managers Swing Menu Component

Introduce to advance swing control


  

Jslider JProgessBar Timer

  

Introduce to Dialog Type of Dialog Working with Dialog

Slide 2/23

Module 1:
    

Introduction to Layout Manager FlowLayout Manager BorderLayout Manager GridLayoutManager CardLayout Manager

Slide 3/23

All Containers in Java whether top-level or general-purpose are based on the concept of Layout managers A layout manager is a Java object associated with a container which governs the placement and size of the component

Slide 4/23

Steps
    

Invoke setLayout() Pass a layout manager class setPreferredSize() setMinimumSize() setMaximumSize()


Demo Code

Working of a Layout Manager




When GUI-based application in Java is executed, the pack() method is invoked. The pack() method invokes the getPreferredSize() method of the frame to determine the best size for laying out the component

Slide 5/23

Java supports different types of Layout manager are:

Slide 6/23

Benefits and Drawbacks


   

Simple to use

Demo Code

Components placed in the center of the container by default Suitable for JApplet which runs as part of a Web Page. If the Container is resized of looses the original alignment, some component may go up or down depending upon the width Complex alignment cannot be achieved

Slide 7/23

The BorderLayout manager allows to add components in the east, west, north, south and center of a container. Benefits and Drawbacks
   

Allows to specify the direction where the component is to placed By default the component is placed in the center Component can added in only four to five location in a container Absolute positioning of component is not possible

Demo Code

Slide 8/23

The GridLayout Manager places the components in terms of rows and columns. Benefits and Drawbacks
 

Demo Code

Simple to use Useful for grouping componets in a rectanglar pattern Each component is of same size Cannot create a complex layout like GridBagLayout where a cell can span more than one row or column

 

Slide 9/23

The CardLayout Manager allows you to stack components one behind another like deck of cards. Only one component is visible at a time and that is the component on top. To display other components, one has to flip them based on.

Slide 10/23

Some methods
   

first(Container parent) next(Container parent) previouse(Container parent) last(Container parent)


Demo Code

Benefits and Drawbacks




Allows several containers and their associated component to share the same space in the container. Not visually appealing as a tabbed pane Requires other components like buttons or drop-down to flip through

 

Slide 11/23

Module 2
  

Menu Components File Dialog box JToolBar

Slide 12/23

A menu system provides a menu bar below the windows title bar. This bar contains items called a menu. When you click a menu it drops down and display various choices called menu items. Each of these menu items is associated with actions to perform desired action. You can choose the task by clicking a menu item
Slide 13/23

 

JMenuBar JMenu
    

JMenu with Separator JMenu with Memonic JMenu with icon JMenu with Accelerator JMenu with Disable
Demo Code

JMenuItem
 

JCheckBoxMenuItem JRadioMenuItem

Slide 14/23

Event Handling


actionPerformed

Methods of JMenuItem
 

isSelected() setSelected(boolean state)

Slide 15/23

A JPopupMenu is menu which pops up when you right click on a container. The popup menu appears exactly at the location where you right clicked.

Demo Code

Slide 16/23

A JFileChooser is a standard dialog box that is used to navigate the file system to:
   

Accept a directory or file name to create a new one Perform operations like open and save, with different labels and buttons. Provide previews and display appropriate icons Display the fiel with required criteria by applying filters.

Slide 17/23

Demo Code


Constructors

Methods of JFileChooser

Slide 18/23

Demo Code


Return value of methods


  

FileChooser.CANCEL_OPTION if you cancel the dialog box JFileChooser.APPROVE_OPTION if you acceptthe file JFileChooser.ERROR_OPTION if an error occurs or the dialog is dismissed.

Slide 19/23

Demo Code


The JFileChooser by default displays all the files in the current directory. However, at times it is requires to display only those files which match certain criteria.

Slide 20/23

JToolBar is similar to a menu bar and contains buttons with icons. These buttons generate events when clicked and can be associated with actions. Dockable JToolBar

Slide 21/23

Constructors

Demo
Demo Code

Slide 22/23

Module 1:
    

Introduction to Layout Manager FlowLayout Manager BorderLayout Manager GridLayoutManager CardLayout Manager

Module 2:
  

Menu Components File Dialog box JToolBar

Slide 23/23

Das könnte Ihnen auch gefallen