Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Initial focused object in container?

Posted on 2005-04-19
Medium Priority
Last Modified: 2010-03-31

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?
Question by:eeBlueShadow
LVL 15

Expert Comment

ID: 13820913
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).
LVL 16

Accepted Solution

gnoon earned 1000 total points
ID: 13822046
Try to call the requestFocus() after the bankContainer is added.
Can you provide a method for call userID.requestFocus() inside BankContainer class?
LVL 10

Author Comment

ID: 13823268
That worked perfectly.

I solved the problem by overriding the Container.requestFocus() method to simply call Component.requestFocus()

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question