Better GUI Controls Orig - For live Java EE training, please ...

fansbutterflyMobile - Wireless

Jul 19, 2012 (5 years and 2 months ago)

501 views

© 2012 Marty Hall
Basic Swing
Basic

Swing

Better GUI Controls
Ori
g
inals of Slides and Source Code for Examples:
http://courses.coreservlets.com/Course-Materials/java.html
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
2
© 2012 Marty Hall
For live Java EE training, please see training courses
at http://courses.coreservlets.com/.
at http://courses.coreservlets.com/.
JSF 2.0, PrimeFaces, Servlets, JSP, Ajax (with jQuery), GWT,
Android development, Java 6 and 7 programming,
SOAP-based and RESTful Web Services, Sprin
g
, Hibernate/JPA,
g
XML, Hadoop, and customized combinations of topics.
Taught by the author of Core Servlets and JSP, More
Servlets and JSP
and this tutorial Available at public
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
Servlets and JSP
,
and this tutorial
.
Available at public
venues, or customized versions can be held on-site at your
organization. Contact hall@coreservlets.com for details.
Topics in This Section
• New features
V AWT

V
s.
AWT
• Basic approach

Summary of Swing components
Summary

of

Swing

components
– Starting points
• JApplet, JFrame
– Swing equivalent of AWT components
• JLabel, JButton, JPanel, JSlider

Swing components that have no AWT equivalent
Swing

components

that

have

no

AWT

equivalent
• JColorChooser, JInternalFrame, JOptionPane, JToolBar,
JEditorPane
Other simple components

Other

simple

components
• JCheckBox, JRadioButton, JTextField, JTextArea,
JFileChooser
4
© 2012 Marty Hall
Overview
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
5
New Features vs AWT
• Many more built-in controls
– Image buttons, tabbed panes, sliders, toolbars, color
choosers, HTML text areas, lists, trees, and tables.

Increased customization of components

Increased

customization

of

components

– Border styles, text alignments, and basic drawing
features. Ima
g
es can be added to almost an
y
control.
g y
• A pluggable “look and feel”
– Not limited to “native” look.

Many miscellaneous small features

Many

miscellaneous

small

features
– Built-in double buffering, tool-tips, dockable toolbars,
keyboard accelerators, custom cursors, etc.
• Model-view-controller architecture
– Can change internal representation of trees, lists, tables.
6
Swing vs. AWT Programming
• Naming convention
– All Swing component names begin with a capital J and
follow the format JXxx. E.g., JFrame, JPanel, JApplet,
JDialog
,JButton.Many are just AWT names with a J.
JDialog
,

JButton.

Many

are

just

AWT

names

with

a

J.
• Lightweight components
– Most Swin
g
com
p
onents are li
g
htwei
g
h
t
: formed b
y

g p
g g
y
drawing in the underlying window.
• Use of paintComponent for drawing
C t d i d i i
i tC t
t i t

C
us
t
om
d
raw
i
ng co
d
e
i
s
i
n
p
a
i
n
tC
omponen
t
, no
t
pa
i
n
t
.
Double buffering turned on by default.

New Look and Feel as default
New

Look

and

Feel

as

default
– With Swing, you have to explicitly set the native look.
• Don't mix Swing and AWT in same window
7
Classic Java Look and Feel
(Metal)
(Metal)
8
htt
p
://download.
j
ava.net/
j
avadeskto
p
/swin
g
set3/Swin
g
Set3.
j
nl
p
New Java Look and Feel
(Nimbus

JDK 1 6 0 10)
(Nimbus


JDK

1
.
6
.
0
_
10)
9
Windows Look and Feel
10
CDE/Motif Look and Feel
11
Setting Native Look and Feel
• Idea
– Many apps use native look, not default “Java” look
– Changing is tedious, so use static method
public class WindowUtilities {
public static void setNativeLookAndFeel() {
try {
try

{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
}

catch(Exception

e)

{
System.out.println("Error setting native LAF: "
+ e);
}
}
}
...
12
Nimbus Look and Feel
• New
I d d i JDK 1 6 0 10

I
ntro
d
uce
d

i
n
JDK

1
.
6
.
0
_
10
• Motivations

Original Java LAF a bit dull compared to modern
Original

Java

LAF

a

bit

dull

compared

to

modern

interfaces
– Windows LAF not updated to be consistent with Vista
and Aero
and

Aero
– Other LAFs did not scale well
• Nimbus based on vector graphics
B t bl

B
e por
t
a
bl
e
– Stick with original Java LAF if Nimbus is unavailable

More info
More

info
– http://developers.sun.com/learning/javaoneonline/
2008/pdf/TS-6096.pdf
13
Setting Nimbus Look and Feel
public static void setNimbusLookAndFeel() {
try {
try

{
LookAndFeelInfo[] lafs =
UIManager.getInstalledLookAndFeels();
for (
LookAndFeelInfo
laf
:
lafs
) {
for

(
LookAndFeelInfo
laf
:

lafs
)

{
if ("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
}
}
}
} catch(Exception e) {
S
y
stem.out.
p
rintln("Error settin
g
Nimbus LAF: " + e);
y p g
}
}
14
Whirlwind Tour of Basic
Components
Components
• Starting points
– JApplet, JFrame
• Swing equivalent of AWT components
JL b l
JB JP l
JSlid

JL
a
b
e
l
,
JB
utton,
JP
ane
l
,
JSlid
er
• New Swing components
JColorChooser
JInternalFrame
JOptionPane
JToolBar

JColorChooser
,
JInternalFrame
,
JOptionPane
,
JToolBar
,
JEditorPane
• Other sim
p
le com
p
onents
p p
– JCheckBox, JRadioButton, JTextField, JTextArea,
JFileChooser
15
© 2012 Marty Hall
Starting Windows:
Starting

Windows:

JA
pp
let and JFrame
pp
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
16
Starting Point 1: JApplet
• Content pane
– A JApplet contains a content pane in which to add
components. Changing other properties like the layout
manager,background color,etc.,also applies to the
manager,

background

color,

etc.,

also

applies

to

the

content pane. Access the content pane through
getContentPane.
L t

L
ayou
t
manager
– The default layout manager is BorderLayout (as with
Frame and JFrame),not
FlowLayout
(as with Applet).
Frame

and

JFrame),

not

FlowLayout
(as

with

Applet).

BorderLayout is really layout manager of content pane.
• Look and feel
– The default look and feel is Java, so you have to
explicitly switch if you want the native look and feel.
17
JApplet: Example Code
import java.awt.*;
import
javax swing
*
;
import

javax
.
swing
.
;
public class JAppletExample extends JApplet {
p
ublic void init
()

{
p () {
WindowUtilities.setNativeLookAndFeel();
Container content = getContentPane();
content.setBackground(Color.WHITE);
content.setLayout(new FlowLayout());
content.add(new JButton("Button 1"));
content.add(new JButton("Button 2"));
t t
dd
(
J
B tt
("B tt 3"))
con
t
en
t
.a
dd
(
new
J
B
u
tt
on
("B
u
tt
on
3"))
;
}
}
18
WindowUtilities is a class I wrote: download it from the Web site.
The code for setNativeLookAndFeel was shown on an earlier slide.
Starting Point 2: JFrame
• Content pane
– JFrame uses content pane in same way as does JApplet.
• Auto-close behavior
JF
l i ll h li k h Cl

JF
rames c
l
ose automat
i
ca
ll
y w
h
en you c
li
c
k
on t
h
e
Cl
ose
button (unlike AWT Frames).
• However, closin
g
the last JFrame does not result in
y
our
g y
program exiting the Java application. To get this behavior,
call setDefaultCloseOperation(EXIT_ON_CLOSE).
– This permits the JFrame to close; however, you won’t be able to
l t h l i i ht i th
Wi d Li t
comp
l
e
t
e any
h
ouse c
l
ean
i
ng as you m
i
g
ht

i
n
th
e
Wi
n
d
ow
Li
s
t
ener.
So, you can still use an explicit exit listener as we did with Frame.
• Look and feel
– The default look and feel is Java (Metal)
19
JFrame: Example Code
public class JFrameExample extends JFrame {
public static void main(String[] args) {
public

static

void

main(String[]

args)

{
JFrame frame = new JFrameExample("This is a test");
frame.setVisible(true);
}
public JFrameExample(String title) {
super(title);
WindowUtilities setNativeLookAndFeel
();
WindowUtilities
.
setNativeLookAndFeel
();
setSize(300, 100);
Container content = getContentPane();
content.setBackground(Color.WHITE);
content.setLayout(new FlowLayout());
content.add(new JButton("Button 1"));
content.add(new JButton("Button 2"));
t t
dd
(
J
B tt ("B tt 3"))
con
t
en
t
.a
dd
(
new
J
B
u
tt
on
("B
u
tt
on
3"))
;
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
20
© 2012 Marty Hall
New Features of Swing
New

Features

of

Swing

Com
p
onents
(
vs. AWT
)
p ( )
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
21
Swing Equivalents of AWT
Components
Components
• JLabel

N
ew features: HTML content images, borders
• JButton
N f i li i

N
ew
f
eatures:
i
cons, a
li
gnment, mnemon
i
cs
• JPanel
New feature:borders

New

feature:

borders
• JSlider

New features:tick marks and labels
New

features:

tick

marks

and

labels
22
JLabel
• Main new feature: HTML content
– If text is "<html>...</html>", it gets rendered as HTML
– HTML labels only work in JDK 1.2.2 or later, or in
Swing 1 1 1 or later
Swing

1
.
1
.
1

or

later
.
– In JDK 1.2 the label string must begin with <html>, not
<HTML>. It is case-insensitive in JDK 1.3 and 1.4.
– JLabel fonts are ignored if HTML is used. If you use
HTML, all font control must be performed by HTML.

You must use <P> not <BR> to force a line break

You

must

use

<P>
,
not

<BR>
,
to

force

a

line

break
.
– Other HTML support is spotty.
• Be sure to test each HTML construct you use. Permitting
th t t HTML t t t ti i ki f
th
e user
t
o en
t
er
HTML

t
ex
t
a
t
run
ti
me
i
s as
ki
ng
f
or
trouble.
• Other new features: ima
g
es
,
borders
23
JLabel: Example Code
String labelText =
"
<html>
<FONT COLOR=WHITE>WHITE</FONT> and
"
+
<html>
<FONT

COLOR=WHITE>WHITE</FONT>

and

+
"<FONT COLOR=GRAY>GRAY</FONT> Text</html>";
JLabel coloredLabel =
new JLabel(labelText JLabel CENTER);
new

JLabel(labelText
,
JLabel
.
CENTER);
...
labelText =
"
<ht l>
<B>B ld</B> d <I>It li </I> T t
</ht l>
"
"
<ht
m
l>
<B>B
o
ld</B>
an
d

<I>It
a
li
c
</I>

T
ex
t
</ht
m
l>
"
;
JLabel boldLabel =
new JLabel(labelText, JLabel.CENTER);
labelText =
"<html>The Applied Physics Laboratory is..." +
"of the Johns Hopkins University." +
"<P>" + ... "...
<
/html
>
";
24
JLabel: Example Output
25
JButton
• Main new feature: icons
1
C
I I
b i h
I I
1
.
C
reate an
I
mage
I
con
b
y pass
i
ng t
h
e
I
mage
I
con
constructor a String representing a GIF or JPG file
(animated GIFs are supported!).
F l t ll
t I
(
tC d B
() )

F
rom an app
l
e
t
, ca
ll
ge
tI
mage
(
ge
tC
o
d
e
B
ase
()

)

normally, then pass resultant Image to ImageIcon.
2.Pass the ImageIcon to the JButton constructor.
Alt ti l ll
tI
I f t th 7 ibl

Alt
erna
ti
ve
l
y, ca
ll
se
tI
con.
I
n
f
ac
t
,
th
ere are
7
poss
ibl
e
images (rollover images, images for when button is
depressed, etc.)

Other features

Other

features
– HTML content as with JLabel
– Alignment: location of image with respect to text
– Mnemonics: keyboard accelerators that let you use Alt-
someChar to trigger the button.
26
JButton: Example Code
import java.awt.*;
import
javax swing
*;
import

javax
.
swing
.
*;
public class JButtons extends JFrame {
public static void main(String[] args) {
public

static

void

main(String[]

args)

{
JFrame frame = new JButtons();
frame.setVisible(true);
}
}
public JButtons() {
supe
r
(
"
Us
in
g

J
B
utto
n"
);
supe ( Us g
J utto
);
WindowUtilities.setNativeLookAndFeel();
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container content =
g
etContentPane
();
g
();
content.setBackground(Color.WHITE);
content.setLayout(new FlowLayout());
27
JButton: Example Code
(Continued)
(Continued)
JButton button1 = new JButton("Java");
content add
(button1);
content
.
add
(button1);
ImageIcon cup = new ImageIcon("images/cup.gif");
JButton button2 = new JButton(cup);
content add
(button2);
content
.
add
(button2);
JButton button3 = new JButton("Java", cup);
content.add(button3);
JButton
button4
=
new
JButton
(
"
Java
"
,cup);
JButton
button4

new

JButton
( Java,

cup);
button4.setHorizontalTextPosition
(SwingConstants.LEFT);
co
n
te
n
t.add
(butto
n4
);
co te t.add
(butto );
pack();
}
}
}
28
JPanel
• Main new feature: borders
– Create a Border object by calling
BorderFactory.createXxxBorder.

Supply the Border object to the JPanel by means of

Supply

the

Border

object

to

the

JPanel

by

means

of

setBorder.
JPanel p = new JPanel();
p setBorder(BorderFactory createTitledBorder("Java"));
p
.
setBorder(BorderFactory
.
createTitledBorder("Java"));
• Other features:

Layout manager settings
Layout

manager

settings
• Can pass the layout manager to the JPanel constructor
– Setting preferred size
Th i JC If t JP l t t lik

Th
ere
i
s no
JC
anvas.
If
you wan
t

JP
ane
l

t
o ac
t

lik
e
Canvas, call setPreferredSize.
29
Standard Borders
• Static methods in BorderFactory
– createEmptyBorder(int top, int left, int bottom, int right)
• Creates an EmptyBorder object that simply adds space
(
mar
g
ins
)
around the com
p
onent.
( g ) p
– createLineBorder(Color color)
– createLineBorder(Color color, int thickness)

Creates a solid
-
color border

Creates

a

solid
-
color

border
– createTitledBorder(String title)
– createTitledBorder(Border border, String title)
Th b d i t h d li l li itl id

Th
e
b
or
d
er
i
s an e
t
c
h
e
d

li
ne un
l
ess you exp
li
c
itl
y prov
id
e a
border style in second constructor.
– createEtchedBorder()
– createEtchedBorder(Color highlight, Color shadow)
• Creates a etched line without the label
30
JPanel: Example Code
public class SixChoicePanel extends JPanel {
public SixChoicePanel(String title,String[] buttonLabels)
public

SixChoicePanel(String

title,

String[]

buttonLabels)

{
super(new GridLayout(3, 2));
setBackground(Color.LIGHT_GRAY);
t d ( d t t itl d d (titl ))
se
t
Bor
d
er
(
Bor
d
erFac
t
ory.crea
t
eT
itl
e
d
Bor
d
er
(titl
e
))
;
ButtonGroup group = new ButtonGroup();
JRadioButton option;
int halfLength
=
buttonLabels.length/2;
int

halfLength

buttonLabels.length/2;

for(int i=0; i<halfLength; i++) {
option = new JRadioButton(buttonLabels[i]);
group.add(option);
add(option);
option = new JRadioButton(buttonLabels[i+halfLength]);
group.add(option);
add(option);
add(option);
}
}
}
31
JPanel: Example Output
• Left window uses createLineBorder
• Right window has three SixChoicePanels
32
JSlider
• Basic use

p
ublic JSlider()
– public JSlider(int orientation)
public JSlider(int min int max)

public

JSlider(int

min
,
int

max)
– public JSlider(int min, int max, int initialValue)

p
ublic JSlider
(
int orientation
,
int min
,
int max
,

p (,,,
int initialValue)
• New features: tick marks and labels
– setMajorTickSpacing
– setMinorTickSpacing
setPaintTicks

setPaintTicks
– setPaintLabels (icons allowed as labels)
33
JSlider: Example Code
JSlider slider1 = new JSlider();
slider1 setBorder( );
slider1
.
setBorder(
...
);
content.add(slider1, BorderLayout.NORTH);
JSlider slider2 = new JSlider();
slider2 setBorder( );
slider2
.
setBorder(
...
);
slider2.setMajorTickSpacing(20);
slider2.setMinorTickSpacing(5);
slider2.setPaintTicks(true);
slider2.setPaintTicks(true);
content.add(slider2, BorderLayout.CENTER);
JSlider slider3 = new JSlider();
s
li
de
r
3.set
B
o
r
de
r
(...);
s de 3.set o de (...);
slider3.setMajorTickSpacing(20);
slider3.setMinorTickSpacing(5);
slider3.setPaintTicks
(
true
);
( );
s l i d e r 3.s e t P a i n t L a b e l s ( t r u e );
c o n t e n t.a d d ( s l i d e r 3, B o r d e r L a y o u t.S O U T H );
34
© 2012 Marty Hall
Swing Components that
Swing

Components

that

Were Not in AWT
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
35
JColorChooser
• Open
– Call JColorChooser.showDialog
• First argument: parent component

Second argument:title string
Second

argument:

title

string
• Third argument: initially-selected Color
• Return value
– Selected Color if “OK” chosen
– null if “Cancel” chosen
36
JColorChooser:
Example Code
Example

Code
• Button that lets you change color of window
public void actionPerformed(ActionEvent e) {
Color bgColor
= JColorChooser.showDialog
(this,
"Choose Background Color",
getContentPane().getBackground());
if (bgColor!= null)
getContentPane().setBackground(bgColor);
}
37
JColorChooser:
Example Output
Example

Output
38
Internal Frames
• MDI: Multiple Document Interface
– Program has one large “desktop” pane that holds all other
windows. The other windows can be iconified
(minimized) and moved around within this desktop pane,
(minimized)

and

moved

around

within

this

desktop

pane,

but not moved outside the pane. Furthermore, minimizing
the desktop pane hides all the contained windows as well.
E l Mi ft P P i t C l D B l d

E
xamp
l
es:
Mi
croso
ft

P
ower
P
o
i
n
t
,
C
ore
l

D
raw,
B
or
l
an
d

JBuilder, and Allaire HomeSite

Swing Support for MDI
Swing

Support

for

MDI
– JDesktopPane
• Serves as a holder for the other windows.
– JInternalFrame
• Acts mostly like a JFrame, except that it is constrained to
stay inside the JDesktopPane.
39
Using JInternalFrame
• Main constructor

p
ublic JInternalFrame(String title,
boolean resizable,
boolean closeable
boolean

closeable
,
boolean maximizable,
b
oolean iconifiable
)
)
• Other useful methods
– moveToFront
– moveToBack
– setSize (required!)
tL ti ( i d!)
– se
tL
oca
ti
on
(
requ
i
re
d!)
40
Internal Frames: Example Code
import java.awt.*;
import
javax swing
*;
import

javax
.
swing
.
*;
public class JInternalFrames extends JFrame {
public static void main(String[] args) {
public

static

void

main(String[]

args)

{
JFrame frame = new JInternalFrames();
frame.setVisible(true);
}
}
public JInternalFrames() {
supe
r
(
"M
u
l
t
i
p
l
e
D
ocu
m
e
n
t
In
te
rf
ace
"
);
supe ( u t p e ocu e t te ace );
WindowUtilities.setNativeLookAndFeel();
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container content =
g
etContentPane
();
g
();
41
Internal Frames: Example Code
(Continued)
(Continued)
JDesktopPane desktop = new JDesktopPane();
desktop setBackground
(
Color LIGHT GRAY
);
desktop
.
setBackground
(
Color
.
LIGHT
_
GRAY
);
content.add(desktop, BorderLayout.CENTER);
setSize(450, 400);
for(int i=0;i<5;i++) {
for(int

i=0;

i<5;

i++)

{
JInternalFrame frame
= new JInternalFrame(("Internal Frame " + i),
true,true,true,true);
true,

true,

true,

true);
frame.setLocation(i*50+10, i*50+10);
frame.setSize(200, 150);
fr
a
m
e.set
B
ac
k
g
r
ou
n
d
(
Co
l
o
r
.
WHITE
);
a e.set ac g ou d
(
Co o.
);
d e s k t o p.a d d ( f r a m e );
f r a m e.m o v e T o F r o n t ( );
f r a m e.s e t V i s i b l e
(
true
);
( );
}
}
}
42
Internal Frames:
Example Output
Example

Output
43
JOptionPane
• Very rich class with many options for
diff f di l b
diff
erent types o
f

di
a
l
og
b
oxes.
• Five main static methods
JO i P h M Di l

JO
pt
i
on
P
ane.s
h
ow
M
essage
Di
a
l
og
• Icon, message, OK button
– JO
p
tionPane.showConfirmDialo
g
p g
• Icon, message, and buttons:
OK, OK/Cancel, Yes/No, or Yes/No/Cancel

JOptionPane showInputDialog (2 versions)

JOptionPane
.
showInputDialog

(2

versions)
• Icon, message, textfield or combo box, buttons
– JOptionPane.showOptionDialog
• Icon, message, array of buttons or other components
44
JOptionPane Message Dialogs
(Windows LAF)
(Windows

LAF)
45
JOptionPane Confirmation
Dialogs (Java LAF)
Dialogs

(Java

LAF)
46
JToolBar
• Acts mostly like a JPanel for buttons
• Dockable: can be dragged and dropped
47
JEditorPane
• Acts somewhat like a text area
• Can display HTML and, if HyperLinkListener
attached, can follow links
48
Other Simple Swing
Components
Components
• JCheckBox

N
ote uppercase B
(vs. Checkb
ox in AWT)

JRadioButton

JRadioButton
– Use a ButtonGroup to
link radio buttons
• JTextField
– Just like AWT TextField except that it does not act as a
d fi ld (
JP dFi ld
f h )
p
asswor
d

fi
e
ld

(
use
JP
asswor
dFi
e
ld
f
or t
h
at
)
• JTextArea
Place in
JScrollPane
if

Place

in

JScrollPane
if

you want scrolling
• JFileChooser
49
© 2012 Marty Hall
Wrap-Up
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
50
More Info
• Oracle Java Tutorial: Swing Summary

http://docs.oracle.com/
j
avase/tutorial/ui/features/components.html
– Very useful summary of most Swing components
• Gives code examples
• Includes graphical table showing each
51
Summary
• Port simple AWT components to Swing by
ddi J f f l
a
ddi
ng
J
to
f
ront o
f
c
l
ass name
• Put custom drawing in paintComponent
C ll
i C
b i i l

C
a
ll
super.pa
i
nt
C
omponent at
b
eg
i
nn
i
ng un
l
ess you turn
off double buffering

Java look and feel is default
Java

look

and

feel

is

default
– But you usually want either new (Nimbus) LAF or
native LAF
• Frames and applets use content pane
– Don’t put anything directly in window
M t t t b d & i

M
os
t
componen
t
s suppor
t

b
or
d
ers
&

i
cons
• Many new components
52
© 2012 Marty Hall
Questions?
Questions?
Customized Java EE Training: http://courses.coreservlets.com/
Java 6 or 7, JSF 2.0, PrimeFaces, Servlets, JSP, Ajax, Spring, Hibernate, RESTful Web Services, Android.
Developed and taught by well-known author and developer. At public venues or onsite at your location.
53