Here you can find the source of textAreaAsLabel(JTextArea textArea)
public static JTextArea textAreaAsLabel(JTextArea textArea)
//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; } }