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.

Problem mit JTextField

Empfohlene Antworten

Veröffentlicht

Hi zusammen,

ich habe folgendes Problem, und zwar möchte ich, nachdem mehr als 4 Zeichen im JTextField sind, das TextField auf setEditable(false) setzten. Das klappt auch schön, nur wie kann ich, wenn ich Backspace drücke dieses dann wieder auf true setzen.

Hier der Code :

import java.awt.Dimension;

import java.awt.FontMetrics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import javax.swing.JTextField;

/**

* @author dvo

*

* To change this generated comment edit the template variable "typecomment":

* Window>Preferences>Java>Templates.

*/

public class DVTextField extends JTextField implements KeyListener {

Dimension prefer;

boolean edit;

private String str;

public DVTextField(String param) {

FontMetrics fm = this.getFontMetrics(this.getFont());

prefer = new Dimension(fm.stringWidth(param + "M"), fm.getHeight());

setColumns(4);

this.addKeyListener(this);

}

public Dimension getMaximumSize() {

return getPreferredSize();

// return prefer;

}

public Dimension getMinimumSize() {

return getPreferredSize();

// return prefer;

}

public void keyTyped(KeyEvent e) {

if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE || this.getText().length() <= 4) {

edit = true;

} else if (this.getText().length() > 4) {

edit = false;

}

this.setEditable(edit);

}

public void keyPressed(KeyEvent e) {

}

public void keyReleased(KeyEvent e) {

}

}

Danke

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.