All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.swingx.plaf.PromptTextAreaUI Maven / Gradle / Ivy

The newest version!
package org.jdesktop.swingx.plaf;

import java.awt.Rectangle;

import javax.swing.JTextArea;
import javax.swing.plaf.TextUI;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;

/**
 * {@link PromptTextUI} implementation for rendering prompts on
 * {@link JTextArea}s and uses a {@link JTextArea} as a prompt component.
 * 
 * @author Peter Weishapl [email protected]
 * 
 */
public class PromptTextAreaUI extends PromptTextUI {
	
    /**
     * Shared prompt renderer.
     */
    private final static JTextArea txt = new JTextArea();

    /**
     * Creates a new {@link PromptTextAreaUI}.
     * 
     * @param delegate
     */
    public PromptTextAreaUI(TextUI delegate) {
        super(delegate);
    }

    /**
     * Overrides {@link #getPromptComponent(JTextComponent)} to additionally
     * update {@link JTextArea} specific properties.
     */
    @Override
    public JTextComponent getPromptComponent(JTextComponent txt) {
        JTextArea lbl = (JTextArea) super.getPromptComponent(txt);
        JTextArea txtArea = (JTextArea) txt;

        lbl.setColumns(txtArea.getColumns());
        lbl.setRows(txtArea.getRows());

        return lbl;
    }

    /**
     * Returns a shared {@link JTextArea}.
     */
    @Override
    protected JTextComponent createPromptComponent() {
        txt.updateUI();
        return txt;
    }

	@Override
	@Deprecated // TODO remove when javax.swing.plaf.TextUI.modelToView is removed	
	public Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException {
		return super.modelToView(t, pos);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy