Java JTextComponent textComponentAsLabel(JTextComponent textcomponent)

Here you can find the source of textComponentAsLabel(JTextComponent textcomponent)

Description

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

License

Apache License

Declaration

public static JTextComponent textComponentAsLabel(JTextComponent textcomponent) 

Method Source Code


//package com.java2s;
/*/*from  w  w  w.j a v a  2 s .c om*/
 * 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.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 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. setTextComponentTransparent( JTextComponent textComponent)
  2. setTextComponentTransparent( JTextComponent textComponent)
  3. setTextComponetIntegerValid(final JTextComponent c)
  4. setTextStyle(JTextComponent txt)
  5. setWarningBackground(JTextComponent comp)
  6. value(JTextComponent txt)