Component reference
Let's look at the scala.swing.Component class in some more detail. As we
have seen, its state can be accessed and modified through attributes
that look like fields (but of course they are implemented as methods,
since setting the attribute causes a change in the look of the
component).
The most important attributes are listed below. Note that all classes
that can be used as components, such as scala.swing.Label,
scala.swing.TextField, scala.swing.Button, as well as our own components,
extend the scala.swing.Component class, and therefore have these same
attributes.
- background is the java.awt.Color of the
component's background;
- foreground is the java.awt.Color of the
component, for instance the text color of a Label;
- font is the java.awt.font of the
component;
- focusable needs to be set to true if the component can
receive keyboard events;
- enabled can be set to false to make the component
passive, it will be grayed out and the user can no longer change any
settings;
- visible can be set to false to make the component
disappear from the window;
- minimumSize, maximumSize, and preferredSize
are of type java.awt.Dimension
- size returns the actual component size;
- tooltip can be set to a string to make a tooltip appear
when the mouse is over the component.