• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

JAVA -- Textbox "KeyPress" EVENT on two textboxes

I have two textboxes (TextBox1 & TextBox2)

Convert below C# code into JAVA
so I can use this one "TextBox_KeyPress"
EVENT on both textboxes.
private void TextBox_KeyPress(
      System.Object sender, KeyPressEventArgs e)
      if (Char.IsLetter(e.KeyChar) && Char.IsLower(e.KeyChar)
        || char.IsWhiteSpace(e.KeyChar))
        e.Handled = true;
1 Solution
Try something like the following :
    private class TextBoxKeyPress extends KeyAdapter {
        public void keyPressed(KeyEvent e) {
            char c = e.getKeyChar();
            if ((Character.isLetter(c) && Character.isLowerCaseChar(c)) ||
                    Character.isWhiteSpaceChar(c)) {
                textBox.append("" + Character.toUpperCase(c));

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now