Solved

JAVA -- Textbox "KeyPress" EVENT on two textboxes

Posted on 2009-07-16
1
588 Views
Last Modified: 2012-05-07
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))
      {
        ((TextBox)sender).AppendText(
          Char.ToUpper(e.KeyChar).ToString());
        e.Handled = true;
      }
    }
0
Comment
Question by:finance_teacher
1 Comment
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24870730
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

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question