• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

Initial focused object in container?


I have the following code (scene and bankContainer are both Container subclasses)

        bankContainer = new BankContainer();

inside the BankContainer constructor:

        userID = new BankSingleLineEntry(0,0,200,30,16); // subclass of Component
        userID.requestFocus(); // I want it to start focussed

However, that component wasn't starting with the focus. Using a debugger I found out it was because the requestFocus() call was failing because the bankContainer had no peer - the bankContainer is added to the scene *after* the BankContainer() constructor and requestFocus are called.

What's the right way to go about setting the initally focused object in a container?
1 Solution
I guess this thread describes your problem: http://www.codeguru.com/forum/archive/index.php/t-31997.html
You can always solve it by calling requestFocus from the paintComponent method of BankContainer (and use a member variable
flag isInitialized to make it happen only once).
Try to call the requestFocus() after the bankContainer is added.
Can you provide a method for call userID.requestFocus() inside BankContainer class?
eeBlueShadowAuthor Commented:
That worked perfectly.

I solved the problem by overriding the Container.requestFocus() method to simply call Component.requestFocus()
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now