Results 1 to 4 of 4

Thread: Click out event

  1. #1
    rulych is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Question Click out event

    Hi!

    I'm creating a GUI with Swing + Substance, and I want to add a JTextField that, when clicking on it, is enabled and set for edition, and, when clicking anywhere else, is disabled again. It's something like text fields for Gmail contacts. My problem is I can't find the way to get that "clicking out" event. May anyone lend me a hand? Thanks a lot!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default

    Try a focus listener. Google is your friend.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    rulych is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    Try a focus listener. Google is your friend.
    Thanks! I'll try that... I'd been already searching on Google, but found nothing, so... :_(

  4. #4
    rulych is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Talking

    I've solved my problem, so I'll post how!

    The JTextField just needs to handle focusLost event, and do there want we want. In addition, I included an event handler for mouseClicked on the window containing the text field (no matter it is inside of a panel that is inside of another panel, etc. xD). Inside of my mouseClicked handler, I requested to obtain the focus with requestFocus(). Now focusLost handler is called even when you click in some part of the window not containing any component ;)

    Thanks to KevinWorkman for the clue on focus listener!

Similar Threads

  1. Double click event
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 11:39 AM
  2. click event
    By raman_v in forum Java Servlet
    Replies: 2
    Last Post: 01-08-2010, 12:05 PM
  3. Swing - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:03 PM
  4. AWT - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:02 PM
  5. How to perform some event to button click
    By eva in forum AWT / Swing
    Replies: 2
    Last Post: 01-16-2008, 12:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •