Example usage for com.jgoodies.forms.layout CellConstraints CENTER

List of usage examples for com.jgoodies.forms.layout CellConstraints CENTER

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout CellConstraints CENTER.

Prototype

Alignment CENTER

To view the source code for com.jgoodies.forms.layout CellConstraints CENTER.

Click Source Link

Document

Put the component in the center.

Usage

From source file:wirschauenplugin.DescriptionInputField.java

License:Open Source License

/**
 * builds a lengthwise limited text area with a remaining-char-counter beneath it.
 *
 * @param maxChars the max length of the text area
 * @param value the default value of the text area
 * @param label the remaining characters label. it must include a %s as placeholder for the counter.
 *///from   ww  w  .ja  v a 2s . c  om
public DescriptionInputField(final int maxChars, final String value, final String label) {
    this.mMaxChars = maxChars;
    this.mLabel = label;

    setLayout(new FormLayout("pref:grow", "fill:50dlu:grow, 3dlu, pref"));
    CellConstraints cellConstraints = new CellConstraints();

    mTextArea = DialogUtil.createTextArea(maxChars); //the text area ensures the length limitation
    mTextArea.getDocument().addDocumentListener(this); //to update the label

    add(new JScrollPane(mTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), cellConstraints.xy(1, 1));

    mCounterLabel = new JLabel(String.format(label, maxChars - mTextArea.getDocument().getLength()));
    add(mCounterLabel, cellConstraints.xy(1, 3, CellConstraints.RIGHT, CellConstraints.CENTER));

    //this fires a event to the document listeners (i.e. this). so be sure, everything is initialized (e.g. counter label)
    String initialValue = null;
    if (value != null) {
        initialValue = value.trim();
    }
    mTextArea.insert(initialValue, 0);

    if (WirSchauenPlugin.getInstance().getSettings().getSpellChecking()) {
        URL dictUrl = getClass().getResource("dictionaries/");
        if (dictUrl != null) {
            SpellChecker.registerDictionaries(dictUrl, "de");
            SpellChecker.register(mTextArea);
        }
    }
}