Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

nurnummern Textfeld

Empfohlene Antworten

Veröffentlicht

Hi,

ich möchte ine Textfeld in das man nur Zahlen von 1-100 eingeben kann. Es dürfen auch keine Kommazahlen möglich sein nur glatte !!

Kann mir einer nen Tipp geben wie ich das anstelle ???

Dickes Danke !!

Gruß Scratch

Das müsste eigentlich mit einem JFormattedTextField funktionieren.

Dem musst du dann im Konstruktor eine Formatmaske übergeben.

z.B

JFormattedTextField jftf = new JFormattedTextField(new DecimalFormat("#,###"));

Welche Formatmaske du da jetzt für dein Anliegen einfügen musst kann ich dir leider auch nicht sagen. Steht aber bestimmt in der Doku

Im Buch Core Java (Band 1), wird für das Problem noch ein anderer Weg gewählt:

Es wird ein normales Textfeld als Grundlage genommen. Man fügt dann einen Key Listener ein, der alle unerwünschten Tastatureingaben konsumiert.


textField.addKeyListener(new KeyAdapter) {
public void keyTyped(KeyEvent evt) {
char ch = evt.getKeyChar();
if (ch < '0' || ch > '9') {
evt.consume();
}
}
}
[/PHP]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.