Can someone explain how to set the focus to a component

Hello,
What is the best way to ensure that a component gets the focus with code. I have tried requestFocus and requestFocusInWindow and none of them seems to do there work. The frame containing the components that should get the focus is displayed, the component is focusable so that is not the problem. What I found out is that if the component is deep in a nesting of panes (where the top pane is in the frame) is that calling requestFocus or requestFocusInWindow does not give the component where this focus is called on the focus but either the pane that contains it, one of the parent panes of this pane or one of the components in these panes, in almost all cases the component requesting the focus does not get the focus at all. I always have to write a work around in defining a focus listener for all these panes that transfer the focus back to the component that requested the focus originally, I can't believe that this is the way to ensure that a component has the focus via code. I have searched for documentation but found nothing on what requestFocus(inWindow) is actually dooing (a lot about focus traversibility but I don't want to control this, just make sure that a component gets the focus).
Again I'm pretty sure that the toplevel window is activated and that the component that requested the focus is focusable (I had created a derived version of the DefaultFocusManager that showed who has focus). Personally I think (and I'm not alone if you do a search in this forum on focus management) that there is either a big problem in the documentation of focus management or that it is still not possible to even try to set the focus on a component in a easy way.
Marc

Hello,
thanks for your reply, here is some example code that illustrates the problem I have (the actual code is to big to show here, which is the raison why I did not posted it here). The code wil create a frame with a JPanel with a JTextField, a 'New' Jbutton and a 'Delete' Jbutton, a tabbed pane in the center ('New' will create a new JPanel, add it to the tabbed pane and set the focus on it, either by calling RequestFocusInWindow() directly or by calling it via InvokeLater (someone on this forum suggested to use this). I changed also the focusmanager to show the component that has the focus when you type something. To test compile and run the program (either with a call to requesteFocusInWindow directly or indirectly (by changing the comments), on my system I get the following behaviour:
1. requestFocusInWindow called directly
Start program en type, the tabbed pane has the focus
Press New and type something, a button has the focus not the created panel
Press New again and type something, a button has the focus not the created panel
2. requestFocusInWindow be called indirectly
Start program and type, the tabbed pane has the focus
Press New and type, the created panel has the focus (I thought at one moment that I had found the solution there, but alas ...)
Press New again and type something, a button has again the focus.
Note that with my real program it is not always a button that will have the focus, sometimes it is a combobox or a TextField (I tried to get this with the example code (the JTextField) but did not succeed.
Hopes this clarify the problem a little bid, what I want is when the window is visible to set focus on newly created panes (or in the real program on the panel that is selected via the tabbed pane or via a key combination to shift the focus between the panels) but requestFocusInWindow seems to behave unpredicatable. I can't imagine that what I see is a bug so I must make some assumptions which are not valid but I don't see them, btw listening on the WindowListener is I think not the solution because the frame is already displayed when I want to set the focus and I do not use a modal dialog box.
The example code follows here
Marc
* Main.java
* Created on December 21, 2004, 8:58 AM
package testfocus;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* @author marc
public class Main
static int counter;
/** Creates a new instance of Main */
public Main()
* @param args the command line arguments
public static void main(String[] args)
JFrame frm=new JFrame();
JPanel content=new JPanel();
frm.setContentPane(content);
final JTabbedPane paneContainer=new JTabbedPane();
JPanel bar=new JPanel();
JButton create=new JButton(new AbstractAction("New")
public void actionPerformed(ActionEvent ev)
counter++;
final JPanel pnl=new JPanel();
pnl.setName("test"+counter);
paneContainer.add(pnl);
pnl.setFocusable(true);
pnl.requestFocusInWindow();
/* Either use this or the previous line
SwingUtilities.invokeLater(new Runnable()
public void run()
pnl.requestFocusInWindow();
JButton delete=new JButton(new AbstractAction("Delete")
public void actionPerformed(ActionEvent ev)
int i=paneContainer.getComponentCount()-1;
if (i>=0)
paneContainer.remove(i);
JTextField dummy=new JTextField("Test");
bar.add(dummy);
bar.add(create);
bar.add(delete);
content.setLayout(new BorderLayout());
content.add(bar,BorderLayout.SOUTH);
content.add(paneContainer,BorderLayout.CENTER);
frm.setSize(300,400);
FocusManager.setCurrentManager(new DefaultFocusManager()
public void processKeyEvent(Component component,KeyEvent ev)
System.out.println("Focus owner"+getFocusOwner());
super.processKeyEvent(component,ev);
frm.setVisible(true);
}

Similar Messages

  • Can someone explain how to set up an administrator account so that I can have my phone and my daughters have separate apple ids?

    I mistakenly updated to the latest version of iOS and ever since then I can send messages to my daughter and I receive them but she does not.  She has an iphone also and her phone is under my apple id also.  Someone told me that I could set up an Administrator Account so that she can still be under my account but she has her own ID and that will fix the problem with text/imessages.  I can't find anything on the website that explains how to do that.  Can someone explain that to me?
    Thanks!

    I'm still not clear on what you are trying to accomplish. If you have an iPhone and she does as well you should have your own Apple IDs.
    If you want to pay for any purchases she makes with her phone as far as apps/music goes than that is what Family sharing is for.
    In my case my Wife and I are setup for family sharing. When she purchases music/apps it charges my credit card. This setup also allows me to share my past music/app purchases with her and vice versa.

  • I am trying to use an external HD and need to configure it for the MAC. Can someone explain how to configure the HD (Western Digital - My Passport SE)?

    Can someone help explain how to add an external HD to the Mac? I have a Western Digital My Passport SE and need to configure if for the MAC and add it to the HD location on my Mac.

    Connect the external drive to the Mac. You can do that while the Mac is on, (If the drive is one that has to be plugged into a wall outlet do that too and turn the power on.) If there is a light on the drive it should turn on.
    Now double click on the hard drive icon - top left of the screen of your computer. When it opens look for the Applications folder. Double click that. Next look for a folder called Utilities. Double click. In there you will see a file called Disk Utility.app. Double click on that.
    You will now see something like this, with two items on the left. The second one is your new drive.
    Select it - one click. And click on Erase - one of the buttons at the top, You will see this.
    You must select the Format, it's a drop down - the one shown in the image above is best. You can change the name from Untitled if you want. The name can be changed later if you prefer.
    At this point look at the bottom right. There is a button there called Erase. Click on it. Then go get yourself a cup of coffee - this will take a few minutes.

  • Can someone explain how to resolve the error "Error al intentar cambiar los módulos"?

    I just reinstalled Lightroom 5, but when i run it, it show the message"Error al intentar cambiar los módulos",
    Does someone know how to fix that? Thanks!

    Error changing modules | Lightroom

  • HT4061 MY ipad has been stolen and i am looking for serial number for insurance purposes can someone explain how to finf the serial number by looking within Itunes and finding hardware that has been used with my itunes account

    any help finding my ipad serial number please
    Thanks

    These links may be helpful.
    How to Track and Report Stolen iPad
    http://www.ipadastic.com/tutorials/how-to-track-and-report-stolen-ipad
    Reporting a lost or stolen Apple product
    http://support.apple.com/kb/ht2526
    Report Stolen iPad Tips and iPad Theft Prevention
    http://www.stolen-property.com/report-stolen-ipad.php
    How to recover a lost or stolen iPad
    http://ipadhelp.com/ipad-help/how-to-recover-a-lost-or-stolen-ipad/
    How to Find a Stolen iPad
    http://www.ehow.com/how_7586429_stolen-ipad.html
    Apple Product Lost or Stolen
    http://sites.google.com/site/appleclubfhs/support/advice-and-articles/lost-or-st olen
    Oops! iForgot My New iPad On the Plane; Now What?
    http://online.wsj.com/article/SB10001424052702303459004577362194012634000.html
    If you don't know your lost/stolen iPad's serial number, use the instructions below. The S/N is also on the iPad's box.
    How to Find Your iPad Serial Number
    http://www.ipadastic.com/tutorials/how-to-find-your-ipad-serial-number
     Cheers, Tom

  • HT5463 In my opinion, when the Silence setting is "only when the device is locked", it contradicts the settings you set above, like Manual. Can someone explain how these settings work together?

    Can someone explain how these settings work together? Manual seams to contraduct the SILENCE setting at the bottom of the Do Not Disturb page. It's very confusing.

    You should have seen information in the support document that you linked from. It used to be with the first version of Do Not Disturb that it would only function when the device was locked. That changed with iOS 7, and not it can be active all of the time. With it on Manual, it is on, but if you have the device "awake" that you can still receive calls/texts, etc. Sort of like you have the phone awake, so it isn't a problem for you to receive things. If you set the settings for Always, this means you can be doing things on the phone and not be disturbed by anything else. Does that make sense?

  • I have just downlaoded the color burst app, can someone explain how to use it?

    I have just downlaoded the color burst app, can someone explain how to use it??
    There is no help in the app and i can't log onto the smart solutions..it is really frustrating me because it is propably a really simple app...can someone please help???

    I posted in this thread an example that illustrates how to use the 3d graph to do surfaces ac lines.
    The type of data that you present to the 3d graph depends on which mthod you are using. In general you want to present a set of points that need plotted. These points are defined by taking one value for each of the XYZ and sometimes W arrays.
    Explanation:
    You want to plot a surface that is defined by four point (X0,Y0,Z0,W0), (X1,Y1,Z1,W1), etc. You can present the values using (4) 2-d arrays each of which have four values at index (o,o), (0,1), (1,0) and (1,1).
    Thie first point plotted would be the point that is defined by taking (0,0) from each of the arrays.
    So as you can see from the above all of your arrays should be of the same size and dimensions for this to work.
    Look at the Example i posted in the other thread and try some small experiments with small data sets before you jump to anything complicated.
    I hope that helps,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Please can someone explain how to delete email addresses?  I have people who when I type in their name it comes up with the correct email address but then when you hit return to confirm it promptly changes the name to someone else (always the same someone

    Please can someone explain how to delete and email address that when typed in brings up one name but when you hit return to confirm it jumps to another name.  I can't find them in my contacts list but they do come up when you type the first few letters of a name.
    EG If I type xyz and the name of the person comes up, when I press return to confirm that's the one I want then it jumps to [email protected],  always the same def address.
    I can't fathom it out.
    Thanks
    Terri

    Try this:
    Start a new email.  In the To address bar, type in xyz like you normally do, press return to confim, and when the address you want to remove shows up in the address bar, move your cursor over the address you want to delete.
    A small triangle next to the name will show up.  click on it, a drop down menu will open, click Remove from Previous Recipients List.  Then do the drop down menu again and Remove Address.
    Good luck.

  • Can someone explain me well when the infopackage use batch or dialog?

    Hi Gurus,
    can someone explain me well when the infopackage use batch or dialog?

    Hi ,
    first of of in Bi_btch job nothin comes in the log .. but if you use PSa and then into data target then it willl definatly create background jobs .. but i feel it doesnt relate to the concept you are taking about ..
    if you us e a sepeate update from PSA step the it will create backgroung jobs ..of  king bi_btch and if you push the packets maually then it will create jobs like bi_book .. thats the diff ..
    The initialization and execution of an InfoPackage is implemented as a process type in the process chain maintenance. The Start Later in Batch setting is hidden if the InfoPackage is used in a process chain. This is because the start of the request is determined by the process chain itself.
    If you do not use the InfoPackage in the process chain maintenance and you want to process the data request in the background, select the radio button Start Later in Batch and define the required start time. If start times already exist for this data request, this is indicated with a  next to the Scheduling Options pushbutton. You can change the start time using Settings Options. You can also enter an end date for the data request with a background job.
    If you schedule an InfoPackage in the batch later, the background request job runs until all data is updated in BW. This is displayed with a corresponding indicator in the Schedule tab page.  The load process remains active until the data is updated.
    For example, this gives external scheduling tools the option of monitoring the request job. The job then also runs with a request from an SAP source system as long as the source system has sent the data to the BW system and posted it or until the monitor sets the request to red. In the job log, a success or error message is displayed according to whether the request was posted successfully or not.
    regards,
    shikha

  • Can someone explain how .prel files work?

    Can someone explain how .prel files work?  My C drive is O/S and programs, my D drive is storage and the project file(s) (the .prel file) are on my E drive. 
    How is this supposed to be more efficient/faster?  P.E. (C drive) has to constantly communicate back and forth across drives with the .prel file and all the files in the subfolders?  It seems like it would be slower. 
    As I mentioned in a previous post; my zooms in/out of the Timeline are VERY slow.  It is almost 1 second before the Timeline gets bigger/smaller.  Any info would be great,thanks!
    Elwood
    Windows 7 64 bit, i7 980x @333 6 core processor, 12 GB ram DDR 1600, Radeon 5850 GPU PE 9

    By using multiple HDD's, one is spreading the I/O (Input/Output) load over various HDD's. The controller is faster than a single HDD, being tasked to read/write from/to multiple places. One of the first laws of physics is that an object cannot be in more than one place, at the same time. The heads on a HDD are no different. If requests for multiple reads are made, the heads will position themselves over on place on the platters, read, and then move to the next requested location, and so on. However, with multiple HDD's, and a good, fast controller, the heads of each HDD will be placed, where necessary, so reads are done at once, from multiple locations.
    For ultimate performance, a good setup would be as follows:
    C:\ system OS and programs (more reading being done here, than writing)
    D:\ Project files (PREL's in this case)
    E:\ RAID 0 Scratch Disks for Media Cache, but not Render files (both reading and writing)
    F:\ RAID 0 Media files (more reading, but also writing)
    G:\ RAID 0 Export/Share and Render files
    Some go so far as to separate out Audio Assets from Video Assets, and use a separate RAID 0 for each
    The downside of that "ultimate performance" setup, is that when a Project is completed, to clean up, one has to go to many HDD's, and locations. There can also be issues when Archiving a Project, because things are scattered about.
    I get "good performance" by having my Project, Copies of my Assets and all Scratch Disks on one HDD. What I give up in performance, I make up for with housekeeping chores, when the Project is done. I still spread my OS/programs from my Projects, with separate physical HDD's.
    Good luck, and hope that this helps,
    Hunt
    PS - Above, I mention RAID 0, but even greater speed can be achieved via many HDD's in the Array, and perhaps a RAID 50. RAID 0 is just two physical HDD's. Also, for RAID, I recommend a dedicated RAID controller card, and NOT software, or the MoBo's RAID capability.

  • Can anybody explain how to configure the Centralized contract in SRM 7

    Hi All,
    Can anybody explain how to configure the Centralized contract management in SRM 7 with ECC EHP4 ?what are all that need to be perform in PI system.
    Thank you,
    praveen

    Hello,
    PI will be required here. You can also refer the config guides maintained at the belwo mentioned location.
    Goto URL http://service.sap.com/srm-inst and then navigate to SAP SRM --> SAP SRM Server 7.0 -> Configuration Guides for SAP SRM 7.0
    Best Regards,
    Rahul

  • How to set the focus to a first element in oracle apex 3.2.1  and 3.1.2.00

    Hello ,
    I am using oracle apex 3.2.1 in development env. How to set the focus to a first element of a page.
    thanks/mahesh

    Hi,
    This might help
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/bldr_pgs.htm#CJGJDHCI
    Find "Cursor Focus" from page Display Attributes
    Br,Jari

  • How to set the focus on the new added line in ALV list (OO)

    Dear Friends,
    I have an ALV list based on OO(using alv_grid->set_table_for_first_display), when I click the 'new' button to add a new line, the mouse arrow is always pointing to the first line - not the new created line for user to input!!.
    So how to set the focus (mouse arrow) on the new added line in ALV list for user to input it friendly?
    Thanks a lot!!

    Hello,
    To get the selected line row first we have get all the rows in the internal table.
    When u click on the button when it is creating the new line we have to pass the row number to the call method
    CALL METHOD <ref.var. to CL_GUI_ALV_GRID > ->get_selected_rows
       IMPORTING
          ET_INDEX_ROWS  =   <internal table of type LVC_T_ROW > (obsolete)
          ET_ROW_NO      =   <internal table of type LVC_T_ROID > .
    CALL METHOD<ref.var. to CL_GUI_ALV_GRID>->set_selected_rows
       EXPORTING
          IT_ROW_NO  =  <internal table of type LVC_T_ROID>
       or alternatively
       IT_INDEX_ROWS  =  <internal table of type LVC_T_ROW>
          IS_KEEP_OTHER_SELECTIONS  =  <type CHAR01>.
    http://help.sap.com/saphelp_erp2004/helpdata/EN/22/a3f5ecd2fe11d2b467006094192fe3/content.htm

  • Can anyone explain how to post the manual entries in BCS?

    Hi All,
    Can anyone explain how to post the manual entries in BCS?

    Dear,
    Depands on posting level.
    There is Manual Posting  under Consolidation Functions.
    Please creat document and task.
    Next you add this task for consolidation monitor. There is "Consolidation Monitor " and you choose Hierarchy task and add your task for manul data.
    In document you kind in mind: choose manula posting !!!!!!!!!!!!!!!!!!!!!  in page tab Propertis under Posting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.
    If you would like to entry in posting level 01 or 10, please choose Local currency and trasaction currency +- group currency.
    If you would like to entry in posting level 20 or 30, please choose Group currency.
    In SEM_BCS are posting level is very important. 
    Regards,
    anka

  • Can someone explain to me what the Terminal does?

    Can someone explain to me what the Terminal application does? A good explanation would be greatly appreciated, thanks!
    NA

    Can someone explain to me what the Terminal
    application does? A good explanation would be greatly
    appreciated, thanks!
    Sure, go here:
    http://www.macdevcenter.com/pub/a/mac/2001/12/14/terminal_one.html
    Powermac G5 - Macbook C2D   Mac OS X (10.4.8)   Both macs are heavily upgraded and used frequently.

Maybe you are looking for

  • Cannot drag a group of photos to C.D for burning.

      I am trying to burn pictures to a C.D and when I drag and drop a group of them to the renamed Disc in finder they do not show up.  In the past I would drag and drop 100-200 pics from iphoto to a blank C.d with no issues. all of sudden this wont wor

  • Query view issue

    Dear All, I am facing a problem in query views. In BW 3.5: When we create a view and save it with technical name which already exists, it gives error and dont allow to overwrite. In BI 7.0: When we create a view and save it with technical name which

  • My project shows following errors

    Hello Sir, Thanks for reply.. when i am executing MyProject code then the following errors were raised: symbol : class File location: class myproject.TexttoImage File fname; symbol : class File location: class myproject.FileLen File fl = new File(s1)

  • Updating Product Categories

    Hi,   We are using SRM 5.0, we initially replicated about 400 Product categories, now due to business requirements, we have consolidated them to 200 in ECC. Now How do I pull the changes in to SRM to inactivate/delete the unused product categories. I

  • Alert Monitor Report

    In the Alert Report, what does Alert Valid from and Alert Valid to fields specifically mean?