5. javax.swing.JTabbedPane
• JTabbedPane()
• JTabbedPane(int)
• TOP
• BOTTOM
• LEFT
• RIGHT
• Component add(Component)
• Component add(Component, int) // index
• void add(String, Component) //title
• void addTab(String, Component) //title
• int getSelectedIndex()
• int getTabCount()
• void removeTabAt(int index)
• void setBackgroundAt(int, Color) // tab index, color
• int setSelectedIndex(int) //index
• setTitleAt(int, String) index, title
GUI Components JFrame JTabbedPane
Instructor: Tanzila Kehkashan
5
6. • Ways of Arranging Components in GUI
• Uses Container class setLayout() method
1. Absolute Positioning
• Provides greatest level of control by setting setLayout method to null. But it can be
tedious to set absolute positioning.
• Methods like setSize, setLocation, and setBounds are used.
2. Layout Managers
• FlowLayout
• BorderLayout
• GridLayout
3. Visual Programming in an IDE
• Provides GUI design tool.
• Supports drag and drop.
Layout Managers
Instructor: Tanzila Kehkashan
6
7. java.awt.FlowLayout
• Default for javax.swing.JPanel
• Components are placed from left to right in order they are added.
• Automatically places components onto next row, if row is full.
• FlowLayout()
• FlowLayout(int) // alignment
Alignment Constants
• FlowLayout.LEFT
• FlowLayout.RIGHT
• FlowLayout.CENTER (default)
• void setAlignment(int)// alignment
• int getAlignment()
Layout Managers FlowLayout
Instructor: Tanzila Kehkashan
7
8. java.awt.BorderLayout
• Default for javax.swing.JFrame
• Arranges components in five regions
• Places upto five components in a container one in each region.
• Automatically displaces previous component, if component is already occupied in the position.
• BorderLayout()
• BorderLayout(int, int) // horizontal gap, vertical gap
Regions
• BorderLayout.NORTH
• BorderLayout.SOUTH
• BorderLayout.EAST
• BorderLayout.WEST
• BorderLayout.CENTER
Layout Managers BorderLayout
Instructor: Tanzila Kehkashan
8
9. java.awt.GridLayout
• Divides container into a grid so that components can be placed in rows and columns.
• Each component has same width and height.
• GridLayout()
• GridLayout(int, int) // rows, columns
• GridLayout(int, int, int, int) // rows, columns, horizontal gap, vertical gap
• int getColumns()
• int getHgap()
• int getRows()
• int getVgap()
• void setColumns(int cols)
• void setHgap(int hgap)
• void setRows(int rows)
• void setVgap(int vgap)
Layout Managers GridLayout
Instructor: Tanzila Kehkashan
9