carookee - group communication for you
Home / JavaForum / Swing + AWT
Infos   |   Features   |   Gold-Edition   |   Kundenservice   
java
  Übersicht
  Forum
Beginner
Java allgemein
JDBC
JNI
Networking
Online-Ressourcen
Swing + AWT
XML
Meckerecke
  Mitglieder
LOGIN





· Passwort vergessen
· Kostenlos anmelden
  Information
  Demo
  Features
  Im Vergleich
  Anmeldung
SUCHE
Beiträge, Foren oder Verfasser finden:
  Kundenservice
  Impressum
  Datenschutz
  AGB
Status
4.990 User online
0 User eingeloggt
 

Beiträge
   Antworten     Neuer Beitrag    

Beitrag 187 von 1460 (13%) |<   <   >   >|

Autor TiSch
Datum 15.01.04, 09:18
Betreff Re: Frage zum JTextField


Hallo,
z.B. so:

import javax.swing.*;
import javax.swing.text.*;

public class MaxLengthTextField extends JFrame
{
    private int maxLength;
    JTextField maxLengthTextField=null;
    
    public MaxLengthTextField(int maxLength){
        this.maxLength=maxLength;
        this.maxLengthTextField = getTextField(maxLength);
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().add(maxLengthTextField);
        this.pack();
        this.setVisible(true);
    }
    
    public JTextField getTextField(final int maxLength){
        JTextField textField=new JTextField(maxLength);
        PlainDocument doc=new PlainDocument(){
            
            public void insertString(int offset, String s,AttributeSet attributeSet){
                if(this.getLength()==maxLength)
                return;
                else
                try{
                    super.insertString(offset,s,attributeSet);
                    }catch(BadLocationException e){}
                }
            };
            textField.setDocument(doc);
            return textField;
        }
        
        public static void main(String[] args)
        {
            new MaxLengthTextField(5);
        }
    }


Grüße,
Tim




Diskussionsverlauf:
Frage zum JTextField
    Re: Frage zum JTextField
    Re: Frage zum JTextField

 Auf diesen Beitrag antworten
 Neuen Beitrag verfassen


|<   <   >   >|

                                                                                                                                                                                                                           

Impressum  · Datenschutz  · AGB  · Infos  · Presse
Ein modernes Forum: teamturn.com