| Method or Constructor
|
Purpose
|
void drawArc(int x, int y, int width, int height, int startAngle, int
arcAngle) |
Draws the outline of a circular or elliptical arc covering the specified rectangle.
|
void drawLine(int x1, int y1, int x2, int y2)
|
Draws a line, using the current color, between the points (x1, y1) and (x2,
y2) in this graphics.
|
void drawOval(int x, int y, int width, int height)
|
Draws the outline of an oval. |
void drawString(String str, int x, int y)
|
Draws the text given by the specified string, using this graphics context's current font and color.
|
void fillArc(int x, int y, int width, int height, int startAngle, int
arcAngle) |
Fills a circular or elliptical arc covering the specified rectangle.
|
void fillOval(int x, int y, int width, int height) |
Fills an oval bounded by the specified rectangle with the current color. |
void fillRect(int x, int y, int width, int height) |
Fills the specified rectangle. |
Color getColor(), void setColor(Color) |
Gets and sets this graphics context's current color. |
Font, getFont(),void setFont(Font font) |
Sets this graphics context's font to the specified font. |
Setting or Getting the Button's Contents
| Method or Constructor
|
Purpose
|
JButton(String, Icon)
JButton(String)
JButton(Icon)
JButton()
|
Create a JButton instance,
initializing it to have the specified text/image.
|
void setText(String)
String getText()
|
Set or get the text displayed by the button.
|
void setIcon(Icon)
Icon getIcon()
|
Set or get the image displayed by the button
when the button isn't selected or pressed.
|
void setDisabledIcon(Icon)
Icon getDisabledIcon()
|
Set or get the image displayed by the button
when it's disabled.
If you don't specify a disabled image,
then the look and feel creates one
by manipulating the default image.
|
void setPressedIcon(Icon)
Icon getPressedIcon()
|
Set or get the image displayed by the button
when it's being pressed.
|
void setSelectedIcon(Icon)
Icon getSelectedIcon()
void setDisabledSelectedIcon(Icon)
Icon getDisabledSelectedIcon()
|
Set or get the image displayed by the button
when it's selected.
If you don't specify a disabled selected image,
then the look and feel creates one
by manipulating the selected
image.
|
setRolloverEnabled(boolean)
boolean getRolloverEnabled()
void setRolloverIcon(Icon)
Icon getRolloverIcon()
void setRolloverSelectedIcon(Icon)
Icon getRolloverSelectedIcon()
|
Use setRolloverEnabled(true) and
setRolloverIcon(someIcon)
to make the button display the specified icon
when the cursor passes over it.
|
Fine Tuning the Button's Appearance
| Method or Constructor
|
Purpose
|
void setHorizontalAlignment(int)
void setVerticalAlignment(int)
int getHorizontalAlignment()
int getVerticalAlignment()
|
Set or get where in the button its contents should be placed.
The AbstractButton class allows
any one of the following values
for horizontal alignment:
LEFT,
CENTER (the default), and
RIGHT.
For vertical alignment:
TOP,
CENTER (the default), and
BOTTOM.
|
void setHorizontalTextPosition(int)
void setVerticalTextPosition(int)
int getHorizontalTextPosition()
int getVerticalTextPosition()
|
Set or get where the button's text should be placed,
relative to the button's image.
The AbstractButton class allows
any one of the following values
for horizontal position:
LEFT,
CENTER, and
RIGHT (the default).
For vertical position:
TOP,
CENTER (the default), and
BOTTOM.
|
Setting or Getting the Label's Contents
| Method or Constructor
|
Purpose
|
JLabel(Icon)
JLabel(Icon, int)
JLabel(String)
JLabel(String, Icon, int)
JLabel(String, int)
JLabel()
|
Create a JLabel instance,
initializing it to have the specified text/image/alignment.
The int argument
specifies the horizontal alignment
of the label's contents within its drawing area.
The horizontal alignment must be one of the following constants
defined in the
SwingConstants interface (which JLabel implements):
LEFT, CENTER, RIGHT,
LEADING, or TRAILING.
|
void setText(String)
String getText()
|
Set or get the text displayed by the label.
|
void setIcon(Icon)
Icon getIcon()
|
Set or get the image displayed by the label.
|
Fine Tuning the Label's Appearance
| Method
|
Purpose
|
void setHorizontalAlignment(int)
void setVerticalAlignment(int)
int getHorizontalAlignment()
int getVerticalAlignment()
|
Set or get where in the label its contents should be placed.
The
SwingConstants interface defines five possible values for horizontal alignment:
LEFT (the default for text-only labels),
CENTER (the default for image-only labels),
RIGHT,
LEADING, and
TRAILING.
For vertical alignment:
TOP,
CENTER (the default), and
BOTTOM.
|
void setHorizontalTextPosition(int)
void setVerticalTextPosition(int)
int getHorizontalTextPosition()
int getVerticalTextPosition()
|
Set or get where the button's text should be placed,
relative to the button's image.
The
SwingConstants interface defines three possible values
for horizontal position:
LEFT,
CENTER, and
RIGHT (the default).
For vertical position:
TOP,
CENTER (the default), and
BOTTOM.
|
Managing a Container's Components
| Method
|
Purpose
|
void add(Component)
void add(Component, int)
void add(Component, Object)
void add(Component, Object, int)
void add(String, Component)
|
Add the specified component to the panel.
When present, the int
parameter is the index of the component
within the container.
By default, the first component added is at index 0,
the second is at index 1, and so on.
The Object parameter
is layout manager dependent and typically provides
information to the layout manager regarding positioning
and other layout constraints for the added component.
The String parameter
is similar to the Object parameter.
|
int getComponentCount()
|
Get the number of components in this panel.
|
Component getComponent(int)
Component getComponentAt(int, int)
Component getComponentAt(Point)
Component[] getComponents()
|
Get the specified component or components.
You can get a component based on its index or x, y position.
|
void remove(Component)
void remove(int)
void removeAll()
|
Remove the specified component(s).
|
Setting or Getting the Field's Contents
| Method or Constructor
|
Purpose
|
JTextField()
JTextField(String)
JTextField(String, int)
JTextField(int)
|
Create a text field.
When present, the int argument specifies the desired width
in columns.
The String argument contains the field's initial text.
|
JPasswordField()
JPasswordField(String)
JPasswordField(String, int)
JPasswordField(int)
|
Create a password field.
When present, the int argument specifies the desired width
in columns.
The String argument contains the field's initial text.
|
void setText(String)
String getText()
|
Set or get the text displayed by the text field.
Note that getText does not work for
password fields.
|
char[] getPassword()
(in JPasswordField)
|
Set or get the text displayed by the text field.
|
Fine Tuning the Field's Appearance
| Method or Constructor
|
Purpose
|
void setEditable(boolean)
boolean isEditable()
|
Set or get whether the user can edit the text in the text field.
|
void setColumns(int);
int getColumns()
|
Set or get the number of columns displayed by the text field.
This is really just a hint for computing the field's preferred width.
|
Font getFont();
void setFont(Font)
|
Set or get font displayed by the text area.
|
void setHorizontalAlignment(int);
int getHorizontalAlignment()
|
Set or get how the text is aligned horizontally within its area.
You can use JTextField.LEFT,
JTextField.CENTER,
and JTextField.RIGHT for arguments.
|
void setEchoChar(char)
char getEchoChar()
(in JPasswordField)
|
Set or get the echo character -- the character displayed
instead of the actual characters typed by the user.
|
Fine Tuning the Field's Appearance
| Method or Constructor
|
Purpose
|
boolean getLineWrap(),
void setLineWrap(boolean)
|
Gets or sets the line-wrapping policy of the text area.
If set to true the lines will be wrapped if they are too long to fit within the allocated width.
If set to false, the lines will always be unwrapped. By default this property is false.
|
void setWrapStyleWord(boolean),
boolean getWrapStyleWord()
|
Set the style of wrapping used if the text area is wrapping lines.
If set to true the lines will be wrapped at word boundaries (whitespace)
if they are too long to fit within the allocated width.
If set to false, the lines will be wrapped at character boundaries. By default this property is false.
|
void setEditable(boolean)
boolean isEditable()
|
Set or get whether the user can edit the text in the text field.
|
void setColumns(int);
int getColumns()
int getRows()
setRows(int rows)
|
Set or get the number of columns, rows displayed by the text area.
|
Font getFont();
void setFont(Font)
|
Set or get font displayed by the text area.
|