A
Panel
represents a simple container that is implemented using Java's
AWT Panel class.
Panels organize components and let you impose a structure on them,
(e.g., several equal sized buttons), that might otherwise be
difficult or impossible.
Panels do not create windows, which means you only see them when
they are in a visible
Frame,
Dialog,
or
Window.
Yoix programs normally interact with a
Panel
using event handlers and by reading or writing the following fields:
| background |
The
Color
that is used to paint the background of the panel.
It is also the default background color assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current color.
Writing immediately sets the panel's background,
and the background of components contained in the panel
that do not pick their own, to the new color.
| | backgroundhints |
An
int
that controls how
backgroundimage
is displayed in the panel.
The value should be one of
SCALE_AREA,
SCALE_DEFAULT,
SCALE_FAST,
SCALE_NONE,
SCALE_REPLICATE,
SCALE_SMOOTH,
or
SCALE_TILE,
which are all defined in
yoix.image.
SCALE_NONE
places the unscaled image in the upper left corner of the panel,
while
SCALE_TILE
(the default) tiles the entire panel with the unscaled image.
The other values select the algorithm used to scale
backgroundimage
so it fills the entire panel.
Reading returns the current hints.
Writing immediately repaints the panel using the new hints to
display the background image.
| | backgroundimage |
An
Object
that should be an
Image
or
String
that identifies an image that is automatically displayed as part of the
panel's background in a way that is controlled by the value assigned to
backgroundhints.
A
NULL
value, which is the default, means there is no image.
A
backgroundimage
that is a
String
should name a local a file or URL that contains a GIF or JPEG image.
Reading returns the current image.
Writing immediately repaints the panel using the new image.
| | components |
A
Dictionary
maintained by the interpreter's layout machinery that maps
tag
fields to actual components;
every component contained in the panel has an entry in the dictionary.
Add the panel to another container (e.g., a frame or panel)
and entries in the
components
dictionary are copied into the new container's
components
dictionary.
In addition, the
root
field in each component is automatically set to the top-level container,
so the
components
dictionary is easy to find, and that means individual components
can find each other by name using the
root.components
dictionary.
| | cursor |
An
Object
that should be an
int,
Image,
or
String
that selects the cursor shown when the pointer is over the panel.
It is also the default cursor assigned to components in the panel's
layout
array that do not pick their own.
A
cursor
that is an
int
should be one of the cursors defined in the
yoix.awt.Cursor
dictionary.
A
cursor
that is an
Image
can describe the cursor using its
size
and
hotspot
fields and often draws it using its
paint
function.
A
cursor
that is a
String
should be the name of a cursor that is already defined in
yoix.awt.Cursor
or the name a local a file or URL that contains a GIF or JPEG image
that will be used as the cursor.
Reading returns the current cursor.
Writing immediately sets the panel's cursor,
and the cursor of components contained in the panel
that do not pick their own, to the new value.
A panel that does not set its own cursor uses
DEFAULT_CURSOR.
| | enabled |
An
int
that is
1
when the panel,
or any of the components contained in the panel,
can respond to user input, and
0
otherwise.
Reading returns the current state.
Writing immediately sets the panel's state to the new value.
| | focusable |
An
int
that is non-zero (the default)
when the panel can accept the keyboard focus and zero
when it can not.
Reading returns the panel's current focusable state.
Writing immediately changes the panel's focusable state to the new value,
which means the focus is automatically transferred if the new value is zero
and the panel is the current focus owner.
| | focusowner |
A read-only
int
that is non-zero when the panel has the focus.
| | font |
The
Font,
or font name if it is a
String,
that is used as the default font assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current font.
Writing immediately changes the panel's font,
and the font used by all components contained in the panel
that do not pick their own, to the new font.
| | foreground |
The
Color
that is used as the default foreground color assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current color.
Writing immediately sets the panel's foreground,
and the foreground of components contained in the panel
that do not pick their own, to the new color.
| | fronttoback |
An
int
that is
1
when components that appear earlier in the
layout
array are placed on top of components that appear later, and
0
when the stacking order is reversed.
In practice,
GridBagLayout
and
CardLayout
are only layout managers where stacking components makes sense.
Reading returns the current stacking order.
Writing immediately tries to change the stacking order.
| | graphics |
A
Graphics
object that defines properties and built-ins that are used to apply
graphics operations to this panel.
Writing after a panel has been created is not allowed and will result in an
invalidaccess
error.
| | layout |
An
Array
of objects, often just components, that the
layoutmanager
arranges in the panel.
Reading returns the current array.
Writing immediately clears panel and then arranges the new
set of components in the panel.
| | layoutmanager |
A
LayoutManager
that takes components from the
layout
array, arranges them in the panel, updates the panel's
components
dictionary, and makes sure the
root
field in each component is set to the panel.
Reading returns the current layout manager.
Writing, when
validate
is non-zero, immediately clears the panel and then rearranges
the components in the
layout
array using the new layout manager.
Yoix panels use a
FlowLayout
as their default layout manager.
| | location |
A
Point
that determines the location of the panel
in a coordinate system that has its origin at the upper left corner
of the container closest to the panel (in the component hierarchy)
that actually contains it, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
Reading returns a snapshot of the current location.
Writing is allowed, but layout managers usually get the final say, so setting
location
should be viewed as a request that may not be honored.
| | nextcard |
An
Object
that
CardLayout
layout managers use to pick the next component that is displayed in the
panel.
See the description of
CardLayout
for more details.
| | paint([Rectangle rect]) |
A
Function
that is called, if it is not
NULL,
whenever the panel needs to be painted.
The optional
rect
argument describes the rectangle that needs repainting in the
coordinate system specified by
graphics.CTM,
which by default has its origin at the panel's upper left corner,
positive x to the right, positive y down, and a resolution of 72 dots per inch.
| | popup |
A
PopupMenu
that is associated with the panel.
Reading returns the current popup menu.
Writing immediately shows the popup menu at the point in the panel's coordinate
system specified by the popup menu's
location
field, assuming of course that the panel is showing on the screen.
Storing
TRUE
in the popup menu's
visible
field, which was added in release 1.2.0, is an easy way to show the
popup menu that currently belongs to the panel.
| | preferredsize |
A
Dimension
that is used by layout managers when they need to know the panel's
preferred size in units of 72 dots per inch.
A
NULL
value means the panel has no preference.
A non-positive height or width is allowed and simply means the panel
has no preference for that dimension.
Reading returns the current preferred size.
Writing changes the preferred size and immediately notifies
root.layoutmanager,
which means the components contained in
root
may be repositioned and resized.
| | repaint() |
A
Builtin
that tells the panel to completely repaint itself,
which means the background is regenerated and then the panel's
paint
function is called.
Obviously
repaint
should not be called, either directly or indirectly, from the panel's
paint
function, however
erasedrawable
is safe because it does not trigger a
paint
call.
| | requestfocus |
An
int
that can be used to request or transfer the keyboard focus.
Storing a non-zero value in
requestfocus
tries to get the focus.
Storing
0
tries to transfer the focus.
Reading
requestfocus
does not currently return any useful information.
| | root |
An
Object
that is automatically updated by the interpreter's layout machinery
so it is always the top-level object that contains the panel.
For example, put a panel in another panel and
root
will be set to the top-level panel;
add the top-level panel to a frame and the original panel's
root
field will be set to that frame.
A panel's event handlers can use
root
when they need to interact with the other components in the container.
| | showing |
A read-only
int
that is non-zero when the panel is showing on the screen.
| | size |
A
Dimension
that determines the size of the panel
in units of 72 dots per inch.
Reading returns a snapshot of the current size.
Writing is allowed, but layout managers usually get the final say, so setting
size
should be viewed as a request that may not be honored.
| | tag |
A
String
used to identify the panel that is either supplied when
the panel is declared, or automatically generated otherwise.
Add a panel to a container, like a
Frame
or even another
Panel,
and the interpreter's layout machinery updates the
root
field so it points at the top-level container and then adds the panel, as
tag,
to the
root.components
dictionary.
| | validate |
An
int
that is
1
when changing the
layoutmanager
field takes effect immediately, and
0
when the change is delayed, often until after the
layout,
size,
or
validate
fields change.
Storing a
1
in
validate
always runs Java's layout manager, even when nothing has changed.
| | visible |
An
int
that is
1
when the panel is visible, and
0
otherwise.
Reading returns the current visibility.
Writing immediately sets the panel's visibility to the new state.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
Event handlers are functions that must be added to a panel when it is
declared.
The handlers that work with panels are listed below;
the names should be familiar if you have done some Java programming.
The
actionPerformed
and
itemStateChanged
event handlers are only for menus.
| |
| Event Handlers: |
actionPerformed,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragEnter,
dragExit,
dragGestureRecognized,
dragMouseMoved,
dragOver,
drop,
dropActionChanged,
focusGained,
focusLost,
invocationRun,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved
| | |
| Example: |
The program,
import yoix.*.*;
Frame f = {
Dimension size = NULL;
Array layout = {
new TextArea {
int rows = 20;
int columns = 80;
int scroll = VERTICAL;
}, CENTER,
new Panel {
Array layout = {
new Panel {
GridLayout layoutmanager;
Array layout = {
new Button {
String text = "Hello, World";
},
new Button {
String text = "Middle";
},
new Button {
String text = "Exit";
actionPerformed(e) {
exit(0);
}
},
};
},
};
}, SOUTH,
};
};
f.visible = TRUE;
is a simple example that shows how you can get equal sized
buttons using nested panels.
| | |
| See Also: |
BorderLayout,
Button,
Canvas,
CardLayout,
Checkbox,
Choice,
CustomLayout,
Dialog,
FileDialog,
FlowLayout,
Frame,
GridBagLayout,
GridLayout,
Image,
Label,
List,
Menu,
MenuBar,
PopupMenu,
postEvent,
ScrollPane,
Scrollbar,
TableColumn,
TableManager,
TextArea,
TextCanvas,
TextField,
TextTerm,
Window
|
|