Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword or section
Like this
30Activity

Table Of Contents

0 of .
Results for:
No results containing your search query
P. 1
Using Swing Components

Using Swing Components

Ratings: (0)|Views: 1,991|Likes:
Published by api-3792621

More info:

Published by: api-3792621 on Nov 25, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

 
510
Lesson: Using Swing Components
http://java.sun.com/docs/books/tutorial/uiswing/components/jcomponent.html
This lesson gives you the background information you need to use the Swing components, and thendescribes every Swing component. It assumes that you have successfully compiled and run aprogram that uses Swing components, and that you are familiar with basic Swing concepts. Theseprerequisites are covered inGetting Started with SwingandLearning Swing with the NetBeans IDE.
A Visual Index to the Swing Components (Java Look and Feel) A Visual Index to the Swing Components (Windows Look and Feel) 
Before you get started, you may want to check out these pages (from theGraphical User Interfaces lesson in the Core trail) which have pictures of all the standard Swing components, from top-levelcontainers to scroll panes to buttons. To find the section that discusses a particular component, justclick the component's picture.
Using Top-Level Containers 
Discusses how to use the features shared by the
JFrame
,
JDialog
, and
JApplet
classes — contentpanes, menu bars, and root panes. It also discusses the
containment hierarchy
, which refers to thetree of components contained by a top-level container.
The JComponent Class 
Tells you about the features
JComponent
provides to its subclasses — which include almost allSwing components — and gives tips on how to take advantage of these features. This section endswith API tables describing the commonly used API defined by
JComponent
and its superclasses,
Container
and
Component
.
Using Text Components 
Describes the features and API shared by all components that descend from
JTextComponent
. Youprobably do not need to read this section if you are just using text fields (formatted or not) or textareas.
How to... 
Sections on how to use each Swing component, in alphabetical order. We do not expect you to readthese sections in order. Instead, we recommend reading the relevant "How to" sections once you areready to start using Swing components in your own programs. For example, if your program needs aframe, a label, a button, and a color chooser, you should readHow to Make Frames,How to Use Labels,How to Use Buttons, andHow to Use Color Choosers.
Using HTML in Swing Components 
 
511
Describes how to vary the font, color, or other formatting of text displayed by Swing components byusing HTML tags.
Using Models 
Tells you about the Swing model architecture. This variation on Model-View-Controller (MVC)means that you can, if you wish, specify how the data and state of a Swing component are stored andretrieved. The benefits are the ability to share data and state between components, and to greatlyimprove the performance of components such as tables that display large amounts of data.
Using Borders 
Borders are very handy for drawing lines, titles, and empty space around the edges of components.(You might have noticed that the examples in this trail use a lot of borders.) This section tells youhow to add a border to any
JComponent
.
Using Icons 
Many Swing components can display icons. Usually, icons are implemented as instances of the
ImageIcon
class.
Solving Common Component Problems 
This section discusses solutions to common component-related problems.
Questions and Exercises 
Try these questions and exercises to test what you have learned in this lesson.
Using Top-Level Containers
As we mentioned before, Swing provides three generally useful top-level container classes:
JFrame
,
JDialog
, and
JApplet
. When using these classes, you should keep these facts in mind:
 
To appear onscreen, every GUI component must be part of a
containment hierarchy
.A containment hierarchy is a tree of components that has a top-level container as itsroot. We'll show you one in a bit.
 
Each GUI component can be contained only once. If a component is already in acontainer and you try to add it to another container, the component will be removedfrom the first container and then added to the second.
 
Each top-level container has a content pane that, generally speaking, contains(directly or indirectly) the visible components in that top-level container's GUI.
 
You can optionally add a menu bar to a top-level container. The menu bar is byconvention positioned within the top-level container, but outside the content pane.Some look and feels, such as the Mac OS look and feel, give you the option of placingthe menu bar in another place more appropriate for the look and feel, such as at thetop of the screen.
 
512
Note:
Although
JInternalFrame
mimics
JFrame
, internal frames aren't actually top-levelcontainers.Here's a picture of a frame created by an application. The frame contains a green menu bar (with nomenus) and, in the frame's content pane, a large blank, yellow label.You can find the entire source for this example in
TopLevelDemo.java
. Although the example usesa
JFrame
in a standalone application, the same concepts apply to
JApplet
s and
JDialog
s.Here's the containment hierarchy for this example's GUI:As the ellipses imply, we left some details out of this diagram. We reveal the missing details a bitlater. Here are the topics this section discusses:
 
Top-Level Containers and Containment Hierarchies 
 
Adding Components to the Content Pane 
 
Adding a Menu Bar 
 
The Root Pane (a.k.a. The Missing Details) 
Top-Level Containers and Containment Hierarchies
Each program that uses Swing components has at least one top-level container. This top-levelcontainer is the root of a containment hierarchy — the hierarchy that contains all of the Swingcomponents that appear inside the top-level container.As a rule, a standalone application with a Swing-based GUI has at least one containment hierarchywith a
JFrame
as its root. For example, if an application has one main window and two dialogs, thenthe application has three containment hierarchies, and thus three top-level containers. Onecontainment hierarchy has a
JFrame
as its root, and each of the other two has a
JDialog
object as itsroot.

Activity (30)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Tran Cong liked this
ALi liked this
ALi liked this
Akash Kale liked this
gopikrishvg liked this
Shankar Ronaldo liked this
Shankar Ronaldo liked this
Yatin Depolkar liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->