Java JTextArea textAreaAsLabel(JTextArea textArea)

Here you can find the source of textAreaAsLabel(JTextArea textArea)

Description

This will allow selection and copy to work but still retain the label look

License

Apache License

Declaration

public static JTextArea textAreaAsLabel(JTextArea textArea) 

Method Source Code


//package com.java2s;
/*/*from  ww w  .j ava2 s  .  com*/
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 */

import java.awt.Color;

import javax.swing.JTextArea;
import javax.swing.UIManager;

import javax.swing.text.JTextComponent;

public class Main {
    /**
     * This will allow selection and copy to work but still retain the label
     * look
     */
    public static JTextArea textAreaAsLabel(JTextArea textArea) {
        //  Turn on word wrap
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        // Perform the other changes to complete the look
        textComponentAsLabel(textArea);
        return textArea;
    }

    /**
     * This will allow selection and copy to work but still retain the label
     * look
     */
    public static JTextComponent textComponentAsLabel(JTextComponent textcomponent) {
        //  Make the text component non editable
        textcomponent.setEditable(false);
        // Make the text area look like a label
        textcomponent.setBackground((Color) UIManager.get("Label.background"));
        textcomponent.setForeground((Color) UIManager.get("Label.foreground"));
        textcomponent.setBorder(null);
        return textcomponent;
    }
}

Related

  1. setCaretPosition(JTextArea ta)
  2. setCeil(final JTextArea textArea)
  3. setModelValue(JTextArea ta, String value)
  4. setTextSafe(JTextArea textArea, String value)
  5. showMemo(JTextArea memo, boolean visible)
  6. validarArticuloDescripcion(JTextArea descripcion, KeyEvent evt)
  7. validateView(JTextArea view)