How do I detect when a JPanel's children have focus?

I need to paint a "focus border" around a JPanel when one of it's child JComponents gets focus. The border is now problem; it's the getting notified when a child receives focus part. There are several components and I'd prefer not to add code to each of them, I was hoping for a central piece of code to handle all cases.
I'm sure this is very simple, but my brain doesn't seem to be working well today.
Thanks,
Jamie

since 1.4 you can add a PropertyChangeListener with the keyboardFocusManager, listening for a "focusOwner" or "permanentFocusOwner" and check it the new one is a child of the panel or not. In earlier versions you have to add a focusListener to any of the panel's children - as was already mentioned in this thread.
Greetings
Jeanette

Similar Messages

  • How do I synch when my ipod doesn't have enough space for all my imusic?

    How do I synch when my Ipod doesn't have enough space for all my imusic?

    Create one or more playlists containing a selection of music you want on the device and sync those rather than the entire library.
    tt2

  • How to listen for key press when air app does not have focus

    Hi,
    I am developing a application in air and part of the functionality I need is the ability for the app to listen for when a specific key is pressed, even when the air app does not have focus.
    Is there support for this for windows or mac? If not, how might this be accomplished? ANE?    

    Ok Mr. Smartass...Ok
    I'm building a browser that is always open, and when
    a user presses Ctrl+F1 (notice, just those two keys,
    I don't care what else they press...) the browser
    will open up. That way, you don't have to wait for it
    to load all the time.You have two ideas here. One is having a universal key map that always gets ctrl-f1 sent to your app. The other is a program that is constantly running so that you don't have to wait for it to open up. The former is not possible (and this is a good thing) As warneria and I have been saying, it is bad design for an app to try to force an OS to implement this kind of feature.
    If you're not going to help please don't post at all;
    it's a waste of time for both you, me, and anyone
    else who may need help on the same subject. Why wouldBelieve it or not, I am helping you.
    See
    http://www.google.com/search?hl=en&lr=&q=programming+code+side+effects
    and
    http://www.faqs.org/docs/artu/ch04s02.html
    "Doug McIlroy's advice to �Do one thing well� is usually interpreted as being about simplicity. But it's also, implicitly and at least as importantly, about orthogonality."
    anyone in their right mind who's trying to steal
    people's passwords come out and say, "I'm not trying
    to steal people's passwords!"wait, your question is why would someone trying to steal passwords say I'm not trying to steal passwords? I think duplicitous people in their right minds might try to trick you that way.
    Beyond that, even if you're not a malicious hacker - and I am sure you are not - if someone posts a solution to your problem, malicious coders then will have learned how to do it. If you think you're programming or using these forums in a bubble, you are not.

  • My film has not totally downloaded, I did not realise this until it stopped 15 minutes before the end, how do I know when the rented film I have purchased has been fully downloaded. Can I retrieve anyhow

    My film I rented has not fully downloaded I only realised that when it stopped 15 minutes before the end , how do I know when a film has been fully downloaded. Oi would not have thought the film would not have started unless the film was fully downloaded. The film warned me prior to tarting that I only had 48 hours to watch once starting!

    I'm sorry but this is too funny to pass up. 

  • How can I detect when a sub vi finishes

    Hi All,
    I'm new to labview and would like some assistance.
    I have produced a sub vi that generates 2 half sine wave of adjustable frequency and amplitude. These are cascaded to produce a number of cycles. These are all included in a case statement. The false state produces a dc output and the true state produces the sine cycles.
    Before the button is pressed a dc level is output, when it is pressed  a number of sine cycles are out and when they have finished the dc level should reappear.
    I would like to know how to detect the completion of the sub vi in the true case so I can switch the case statement back to false asap.
    I'm having problems with gaps in the output data when the sub vi teminates and the case statement reverts back to the false state.
    Many thanks
    Andy
    Attachments:
    PulseGeneration.vi ‏164 KB
    HalfWaveBlock.vi ‏77 KB

    Hello Andy
    Thank you for getting in touch regarding your problem, I am an applications engineer at National Instruments and I will be supporting you with your query. As I understand you have a case structure which opens a sub vi, runs for a while and then changes back to its original state, and the problem you are having is switching from the vi execution case to an alternative case.
    Thank you for sending in your vi's, I have been able to look at the HalfWaveBlock vi, but have not been able to open the pulse generation vi, could you send this again please? I can then look at your code and possible ways to implement the functionality.
    There are a few options for approaching this task.
    - Time the sub vi execution and add a timing condition to the case structure in your main code.
    - Have a condition in the sub vi that alerts the main vi of completion.
    I have also found some resources which will help you understand the functions you are using and will also give you some ideas for implementing further functionality.
    - Execution Structures: http://zone.ni.com/devzone/cda/tut/p/id/12293
    - VI analyser toolkit: http://zone.ni.com/devzone/cda/tut/p/id/5046
    - Sub Vi indicator: http://digital.ni.com/public.nsf/allkb/26B1D8C3629475B686256DAD005816F6?OpenDocument
    - Timing, Shift Registers and case structures: http://forums.ni.com/t5/forums/replypage/board-id/170/message-id/579608/tab/rich
    There are also a number of examples available through the help tab and example finder window within LabVIEW itself. A few that I recommend looking at are.
    - Dynamic Load Example.vi
    - Dynamically Monitor VI
    If you could look at these resources and send me your code, we can then both continue to work on a solution to this issue.
    Regards
    Stephanie L
    Applications Engineer
    National Instruments UK and Ireland

  • How can I detect when a hibernate mode accures during my program?

    hello everyone
    I 'm trying to find some way to let my program know the moment when the user tries to get the computer into hibernate mode ?
    is this possible in any way under java?

    Since you already know about JNI, and since you've already been told you can't do it in pure Java, what more are you waiting for? You might as well investigate the JNI route. The only other option I see is JNA.

  • How can I detect when a text field changes in Cocoa-Applescript?

    I'm working on an application where I have one text field, and below it, a "Send" button. When the button is pressed, is sends whatever is typed in the field to all the user's Skype contacts. I have to prevent the user from sending a blank message to all contacts, so I have to change the button's setEnabled. I've been using an NSTimer to check every second, which works, but it lags my application hugely. Is there any handler that is run whenever text is added or deleted? Perhaps something like:
    on myTextFieldDidChange_(aNotification)

    A specific text field is not used in the handler call - the delegate method is called for all text fields.  In the case where you have several text fields, you can get the notification's object, for example:
    on controlTextDidChange_(aNotification) -- a text field changed, so check it out
      set thisTextField to aNotification's object() -- the current control being changed
      set theText to thisTextField's stringValue()
      log theText
      -- whatever
    end controlTextDidChange_
    Note that you need to connect the text field's delegate outlet to your AppDelegate (or whatever class you are using for the delegate).

  • How to detect when 2 movie clips have been clicked?

    Hello:
    I'd like to know how can I detect when 2 movie clips have been clicked (irregardles of the order).
    What I have is this:
    In my main timeline I have 2 independent movie clips (mc_him and mc_her) each in it's own layer that, when clicked, play an internal animation without moving my main playhead anywhere. What I need to do is, once they are both clicked (as I said, it doesen't matter in what order), a button that sends me to another section of my movie has to appear. It really doesen't matter if the button shows by enabling it with alpha or by sending me to a specific frame where my button lies. What I need to detect is both clicks so that the button shows up.
    How can I achieve this?
    Thank you very much.

    btn1.onRelease=function(){
    // do whatever
    this.clicked = true;
    checkBothClickedF();
    btn2.onRelease=function(){
    // do whatever
    this.clicked = true;
    checkBothClickedF();
    function checkBothClickedF():Void{
    if(btn1.clicked&&btn2.clicked){
    // do something. both clicked
    // reset both clicked properties?

  • How to detect when new record is created?

    How can I detect when new record is created in PA30? For example, a newly create record for infotype 6 (address).
    Can I get the information in PCL4?

    Hi Irene,
    the field PAnnnn-AEDTM, nnnn is the infotype number, will give you the date when the record was last changed.
    Not sure if you can precisely get the date when the infotype was created. I dont feel the need to read cluster form the same.
    Regards,
    Pulkit

  • Detecting when exception was thrown using custom class loader

    Hello all,
    I would like to implement the solution described here - http://stackoverflow.com/questions/75218/how-can-i-detect-when-an-exceptions-been-thrown-globally-in-java - that uses custom class loader in order to detect when an Exeption thrown somewhere in the JVM hosting my app, please note that exceptions might be thrown from 3rd party jars the app is using. So, thanks to help I got from another post, I've managed to code the custom class loader. My question is how can the class loader wrap the original exception, as the methods in ClassLoader deals with classes, not instances. So where should I set the original exception?
    Thanks!
    Edited by: user9355666 on Sep 28, 2010 10:48 PM

    user9355666 wrote:
    I think I'm missing something fundumental, forgive me for being slow...
    This is what I did so far. For the exception wrapper I made a simple class extens Exception that recieve Exception in its ctor and store it. I also subclassed ClassLoader and override its loadClass(). I've registered it as the system classloader. My thinking was to check in that point that if the requested class is instance of Exception and if yes, returning my wrapper class wrapping this exception. But, since loadClass() return class, how can I set in the wrapper the original exception?
    In addition, let's say 2 different places in the code throws NPE, to my understanding the classloader will load NPE only once, so how throwing the NPE in the second time can be detected?you are missing a key point. you should creating a custom implementation of the NPE class which hooks into your detection code in its constructor. from that point forward, anytime any NPE (which is your custom class) is constructed, you can detect it.

  • Detecting When a Non-Blocking Socket Is Closed by the Remote Host

    Hi,
    Using NIO non blocked sockets how do I detect when a Non-Blocking Socket Is Closed by the Remote Host?
    What I have read is:
    The only way to detect that the remote host has closed the connection is to attempt to read or write from the connection. If the remote host properly closed the connection, read() will return -1. If the connection was not terminated normally, read() and write() will throw an exception.
    I have written a server test program using NIO and an applet connecting to the server program via sockets.
    When I after a successful connection shuts down the browser following happens: The code below comes in an endless loop though mySelector.select returns 0 every time. (The selector is registered for OP_READ). size = 1.
    while (true) {
    int n = mySelector.select();
    int size = mySelector.keys().size();
    if (n == 0) continue;
    Is this an expected result?
    How do I get to know what client has lost connection?
    My environment:
    W2000
    java 1.4.1 build 1.4.1_01-b01
    Browser used: IE 5.0
    Many thanks for your help on this matter!
    Regards Magnus Wistr�m

    What you're doing looks OK to me.
    I wonder whether your thread is being interrupted by Thread.intterupt() somewhere. Try putting a Thread.interrupted() before the select call.
    Sylvia.

  • Detect when user stops scrolling

    I have an application where a user scrolls using scrolldrags, but this always ends up in the user clicking where they stopped scrolling, so I need to stop this. My idea was that I have a variable "changeable" on and off depending on whether the user is scrolling or not, so when they stop scrolling, the objects become changeable again, how do I detect when the user stops scrolling with scrolldrag using the ScrollPane object?

    add a mouseup listener when scrolling begins and apply a stopPropagation() or stopImmediatePropagation() method to that event and remove the listener in the mouseup listener function .

  • Detecting when you leave a frame

    How can i detect when a particular frame is left? i.e. The
    user is viewing fram x, they click one of several buttons or
    perform a particular action which causes the swf to move to a
    different frame how can i detect when it exits the original frame
    x?

    I'm not sure I quite understand your question ... if the user
    clicks a button that will move the playhead ... the playhead will
    leave the frame then, at that time, playhead gone ...?
    unless you have something else that runs before it moves the
    main timeline's playhead ... but in that case then, at the end of
    that action is when the palyhead will leave the frame, place a call
    there to the item that needs notification ...? You don't really
    need anything to detect it.

  • How do you detect url redirects when connecting to a URL

    how do you detect url redirects when connecting to a URL?
    Thanks in advance
    stev

    Hai
    (i) If it a jsp we can get the URL by request object.
    Like
    String url = request.getHeader("Referer");
    u can do it in Servlet aslo by request object variable.
    If this explanation is not ok, Explain ur doubt in more briefed Manner

  • How to detect when a page is in view with jQuery or javaScript?

    Is there a way a detect when a page is in view? Currently it seems that my document ready function is being called when the page is the next or previous page as well as the current page. Seems that this gets called twice... is there a reliable way to detect this?

    I ran into this alot. first thing is that when you are looking at a particular page, DPS is caching the pages around it, all around it, so it caches the top, right, bottom and left pages, which will launch things and play videos and what not.
    Here's the workaround for getting it to only launch when in view. set the autoplay time (I assume this is for a "webcontent overlay") to .125 seconds. it will start the clock only when the page (tile) is in view.
    don't know if theres an easier way, but that's how I do it and it works.

Maybe you are looking for