This page was saved using WebZIP 6.0.8.918 (Unregistered) on 01/20/05 오후 3:27:46.
Address: http://www.leepoint.net/notes-java/18summaries/guisum-containers.html
Title: Java: Summary - GUI Containers  •  Size: 5585  •  Last Modified: Fri, 14 Jan 2005 00:25:14 GMT

Java: Summary - GUI Containers

Top-level Containers: JFrame

JFrame - window, typically subclassed
w = new JFrame(); Constructor
w.setTitle(t); Sets titlebar text to t
w.setDefaultCloseOperation(opt); Use opt JFrame.EXIT_ON_CLOSE to terminate program when close box clicked.
w.setVisible(true/false); Make visible or hide. Also start GUI thread.
w.pack(); Calculates layout on all inner containers and sets size of JFrame.
w.setContentPane(cont); Sets the content pane - common to pass a JPanel here.
cont = w.getContentPane(); Returns the window's content pane.
w.setJMenuBar(mb); Adds a JMenuBar.
w.setResizable(false); Prevent user from resizing window.
w.setLocation(x, y); Positions window's top left corner at screen coordinates (x, y).
w.show(); Use w.setVisible(true).
w.hide(); Use w.setVisible(false).
w.setSize(w, h); Sets window size, but should use layouts and pack() instead.

Top-level Container: JApplet

JApplet - An applet

Top-level Container: Dialogs: JOptionPane, JFileChooser, JColorChooser, JDialog

JOptionPane - Commonly used to create dialogs.

Low-level Containers

JPanel - Set layout and add components to JPanel.
p = new JPanel(); Creates new JPanel
p.setLayout(layout); Sets the panel's layout.
p.add(widget); Adds the widget to next position in Layout (eg, Flow, Grid, or Box layouts).
p.add(widget, constraint); Adds the widget to position defined by constraint (eg, Border or Gridbag layouts).
JScrollPane - Holds textarea, list, (or large images in label) and adds scroll bars as necessary.
scr = new JScrollPane(textarea); Surrounds textarea with scrollbars as needed.
JTabbedPane - Display tabs to allow user to select one of many panels.

Copyleft 2004 Fred Swartz