You are on page 1of 11
Chapter 04 The Tour of Swing JFrame Object java.lang Component Container MenuContainer java.awt Window Interface Frame JFrame javax.swing Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -1- Chapter 04 The Tour of Swing Swing classes Class Description AbstractButton Abstract super-class for Swing buttons. ButtonGroup Encapsulates a mutually exclusive set of buttons. ImageIcon Encapsulates an icon. JApplet The Swing version of Applet. JButton The Swing push button class. JCheckBox The Swing check box class. JComboBox Encapsulates a combo box (a combination of a drop-down list and text field). JLabel The Swing version of a label. JRadioButton The Swing version of a radio button. JScrollPane Encapsulates a scrollable window. JTabbedPane Encapsulates a tabbed window. JTable Encapsulates a table-based control. JTextField The Swing version of a text field. JTree Encapsulates a tree-based control. Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -2- Chapter 04 The Tour of Swing The Swing family tree Object java.lang Component Container JComponent Window Frame JApplet JPanel JFrame JFrame Swing Features ¾ Borders ¾ Graphics Debugging ¾ Easy mouse-less operation ¾ Tool-tips ¾ Easy Scrolling ¾ Pluggable look and feel ¾ New Layout Managers Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -3- Chapter 04 The Tour of Swing JTabbedPane Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -4- Chapter 04 The Tour of Swing JTabbedPane Constructors: JTabbedPane() JTabbedPane(int tabPlacement) JTabbedPane(int tabPlace, int tabLayoutPolicy) Tab Placements: JTabbedPane.TOP JTabbedPane.BOTTOM JTabbedPane.RIGHT JTabbedPane.LEFT Tab layout policy: JTabbedPane.WRAP_TAB_LAYOUT JTabbedPane.SCROLL_TAB_LAYOUT Adding tabs to Tabbed Pane: void addTab(String str, Component comp) Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -5- Chapter 04 The Tour of Swing Different Tab Policies Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -6- Chapter 04 The Tour of Swing WRAP_TAB_LAYOUT SCROLL_TAB_LAYOUT Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -7- Chapter 04 The Tour of Swing Creating a tabbed pane Create a JTabbedPane Object Call addTab( ) method to add tabs on the pane Repeat above step for each tab Add tabbed pane to the content pane of applet Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -8- Chapter 04 The Tour of Swing Example: public class JTabDemo extends JApplet { public void init( ) { JTabbedPane jtp = new JTabbedPane( ); jtp.addTab("Languages", new LanPanel( )); jtp.addTab("Colors", new ColorsPanel( )); jtp.addTab("Flavors", new FlavorsPanel( )); getContentPane( ).add(jtp); } } class LanPanel extends JPanel { public LanPanel( ) { JButton b1 = new JButton("English"); add(b1); JButton b2 = new JButton("Spanish"); add(b2); JButton b3 = new JButton("Arabic"); add(b3); JButton b4 = new JButton("French"); add(b4); } } Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. -9- Chapter 04 The Tour of Swing JScrollPane Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. - 10 - Chapter 04 The Tour of Swing Advanced Java Programming (TYIF) 2008-2009 by Kute T. B. - 11 -