Solved

selecting tab and enabling selection border.

Posted on 2004-04-14
16
287 Views
Last Modified: 2011-10-03
i have JTabbedPane and selecting tab using setSelectedIndex(int index) or setSelectedComponent(Component component) does not set focus to the tab. how do i select the tab and also set focus to the selected tab?
0
Comment
Question by:sharath_kulal
  • 4
  • 4
  • 3
  • +2
16 Comments
 
LVL 9

Expert Comment

by:Nick_72
ID: 10822279
try to call requestFocus();
0
 
LVL 9

Expert Comment

by:Nick_72
ID: 10822286
..on the selected tab I mean...
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10822290
setSelectedIndex should select the tab.  Can you post the code.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 10822312
try

         yourTabbedPane.setSelectedIndex(1);

followed by

         yourTabbedPane.getSelectedComponent().requestFocus();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10822317
>> setSelectedIndex should select the tab.
Hi mmuru,
the author doesn't say it doens't select the tab, he wants it to have the focus too
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10822330
>> does not set focus to the tab

This where I got confused...
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10822333
>>  how do i select the tab

This is one another to my confusion... :)
0
 
LVL 1

Author Comment

by:sharath_kulal
ID: 10822676
TabbedPane.setSelectedIndex(1);
TabbedPane.getSelectedComponent().requestFocus();

does select the tab but still does not set focus to the tab.
my concern is not how to select the tab but how to set focus to the selected tab.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:Nick_72
ID: 10822794
Well, normally a selected component gets the focus when you click it, like for example when you click a JTextField. How do you know the tab hasn't got the focus, and which component has the focus instead of the that tab? How does that component indicate it has focus?

/Nick
0
 
LVL 92

Expert Comment

by:objects
ID: 10828155
try:
TabbedPane.requestFocus();
0
 
LVL 1

Author Comment

by:sharath_kulal
ID: 10857872
well this code worked. just invoke set focus in another thread.
thanks for ur valuble inputs.

 EventQueue.invokeLater(new Runnable() {
        public void run() {
                tabbedPane.getSelectedComponent().requestFocusInWindow();
        }
 });
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10872360
Hi, don't you think my comment was a useful one then?
If you do: then kindly accept my comment...

If you don't: ask at EE support to delete this Q and refund the points
But please don't leave a Q open like that.
0
 
LVL 92

Expert Comment

by:objects
ID: 10874987
didn't Nick72 already state that?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10875623
Thanks for accepting
0
 
LVL 9

Expert Comment

by:Nick_72
ID: 10876957
LOL...well what can I say...

if (comment_from_someone_else.wasUseful()) {
  doNotAccept();
  EESupport.requestDeleteAndRefund();
}
else if (zzynx_comment.wasUseful()) {
  zzynx_comment.accept();
}

  _  _
    c
   __/
 

   
0
 
LVL 92

Expert Comment

by:objects
ID: 10883233
We'll all have to start 'asking' people to accept our comments :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now