FileDocCategorySizeDatePackage
BasicTextFieldUI.javaAPI DocJava SE 5 API12369Fri Aug 26 14:58:06 BST 2005javax.swing.plaf.basic

BasicTextFieldUI

public class BasicTextFieldUI extends BasicTextUI
Basis of a look and feel for a JTextField.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

author
Timothy Prinzing
version
1.95 12/19/03

Fields Summary
Constructors Summary
public BasicTextFieldUI()
Creates a new BasicTextFieldUI.

	super();
    
Methods Summary
public javax.swing.text.Viewcreate(javax.swing.text.Element elem)
Creates a view (FieldView) based on an element.

param
elem the element
return
the view

	Document doc = elem.getDocument();
	Object i18nFlag = doc.getProperty("i18n"/*AbstractDocument.I18NProperty*/);
	if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
	    // To support bidirectional text, we build a more heavyweight
	    // representation of the field.
	    String kind = elem.getName();
	    if (kind != null) {
		if (kind.equals(AbstractDocument.ContentElementName)) {
		    return new GlyphView(elem);
		} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
		    return new I18nFieldView(elem);
		}
	    }
	    // this shouldn't happen, should probably throw in this case.
	}
	return new FieldView(elem);
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)
Creates a UI for a JTextField.

param
c the text field
return
the UI

        return new BasicTextFieldUI();
    
protected java.lang.StringgetPropertyPrefix()
Fetches the name used as a key to lookup properties through the UIManager. This is used as a prefix to all the standard text properties.

return
the name ("TextField")

	return "TextField";
    
public voidinstallUI(javax.swing.JComponent c)

        super.installUI(c);
	updateBackground((JTextComponent)c);
    
protected voidpropertyChange(java.beans.PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent. This is a hook which UI implementations may change to reflect how the UI displays bound properties of JTextComponent subclasses.

param
evt the property change event

	if (evt.getPropertyName().equals("editable") ||
	    evt.getPropertyName().equals("enabled")) {

	    updateBackground((JTextComponent)evt.getSource());
	}
    
private voidupdateBackground(javax.swing.text.JTextComponent c)

	Color background = c.getBackground();
	if (background instanceof UIResource) {
	    Color newColor = null;
	    String prefix = getPropertyPrefix();
	    if (!c.isEnabled()) {
		newColor = DefaultLookup.getColor(c, this,
						  prefix + ".disabledBackground",
						  null);
	    }
	    if (newColor == null && !c.isEditable()) {
		newColor = DefaultLookup.getColor(c, this,
						  prefix + ".inactiveBackground",
						  null);
	    }
	    if (newColor == null) {
		newColor = DefaultLookup.getColor(c, this,
						  prefix + ".background",
						  null);
	    }
	    if (newColor != null && newColor != background) {
		c.setBackground(newColor);
	    }
	}