Solved

selecting tab and enabling selection border.

Posted on 2004-04-14
16
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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
 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

705 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