Package shared.tabtextfield

Source Code of shared.tabtextfield.JTabTextField

/*
*  JTabTextField.java
*
*  Created on 04.10.2009, 17:33:55
*
*  Copyright (C) 04.10.2009, 17:33:55  <reiner>

*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

package shared.tabtextfield;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JTextField;
import javax.swing.text.Document;


public class JTabTextField extends JTextField
{
    public JTabTextField()
    {
        super();
        doInit();
    }

    public JTabTextField(Document doc, String text, int columns)
    {
        super(doc, text, columns);
        doInit();
    }
   
    public JTabTextField(int columns)
    {
        super(columns);
        doInit();
    }

    public JTabTextField(String text)
    {
        super(text);
        doInit();
    }

    public JTabTextField(String text, int columns)
    {
        super(text, columns);
        doInit();
    }

    protected void doInit()
    {
        addFocusListener(new FocusAdapter()
        {
            public void focusGained(FocusEvent ev)
            {
                if (isEditable())
                {
                    String str = getText();
                    setSelectionStart(0);
                    setSelectionEnd(str.length());
                }
            }
            public void focusLost(FocusEvent ev)
            {
                if (isEditable())
                {
                    setSelectionStart(0);
                    setSelectionEnd(0);
                }
            }
        });
    }
}
TOP

Related Classes of shared.tabtextfield.JTabTextField

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.