Java Reference
In-Depth Information
State: The editable and focusTraversable properties describe various states of the text
components. The editable property allows you to make a text component read-only.
For the read-only focusTraversable property, text components are in the focus cycle
(that is, they can be tabbed into) when they're enabled. The focusAccelerator is used
when a neighboring JLabel has the text component set in its labelFor property, allowing
you to use the visible mnemonic of the JLabel to move focus into the text component.
The componentOrientation setting describes how the component's text will be drawn.
Use this for languages like Hebrew where left-to-right is not necessarily the best way to
draw characters. The JTextComponent inherits an opaque property from JComponent .
When the opaque property is set to false , the contents of the area behind the text compo-
nent bleed through, allowing you to have an image background if desired. See Figure 15-2
for how this might appear.
Listing 15-1 is the source code used to generate Figure 15-2. If you comment out the
setOpaque(false) line, a background image will not be shown.
Figure 15-2. An opaque text component with an image background
Listing 15-1. Drawing in the Background of a Component
import javax.swing.*;
import java.awt.*;
public class BackgroundSample {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Background Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final ImageIcon imageIcon = new ImageIcon("draft.gif");
JTextArea textArea = new JTextArea() {
Image image = imageIcon.getImage();
Image grayImage = GrayFilter.createDisabledImage(image);
{setOpaque(false);} // instance initializer
 
Search WWH ::




Custom Search