Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: KeyEvent Running Twice?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default KeyEvent Running Twice?

    private void txtSearchKeyTyped(java.awt.event.KeyEvent evt) {
    if (jComboSelection.getSelectedIndex() == 0)
    {
    if (txtSearch.getText().length() == 4)
    {
    } else if (txtSearch.getText().length() == 5)
    {
    txtSearch.remove(5);
    }
    }
    }

    This is running twice; i.e trying to delete index 5 twice == error :/ .. can someone tell me how you can make it run once please? ... and is this the best way to do it?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: KeyEvent Running Twice?

    We have no way of knowing what this code is doing without the code that sets it up. Please do not post your whole program, just an SSCCE that demonstrates the problem. Don't forget the highlight tags.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: KeyEvent Running Twice?

    This is running twice;
    Must be some code is calling that method two times. Where is that method called from?
    Print out the event object to see what information it has. Maybe that will tell you what is happening.

Similar Threads

  1. JApplet Not Running In Firefox
    By aussiemcgr in forum Java Theory & Questions
    Replies: 13
    Last Post: August 13th, 2011, 08:40 AM
  2. Running out of ideas...
    By Cat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2011, 11:21 AM
  3. 'Run' isn't 'Running'
    By leonsas in forum AWT / Java Swing
    Replies: 5
    Last Post: December 27th, 2010, 01:37 PM
  4. Running a external exe in Mac OS
    By supertreta in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 15th, 2010, 01:32 PM
  5. Replies: 1
    Last Post: March 3rd, 2009, 08:04 AM