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

selecting tab and enabling selection border.

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
sharath_kulal
Asked:
sharath_kulal
  • 4
  • 4
  • 3
  • +2
1 Solution
 
Nick_72Commented:
try to call requestFocus();
0
 
Nick_72Commented:
..on the selected tab I mean...
0
 
mmuruganandamCommented:
setSelectedIndex should select the tab.  Can you post the code.
0
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!

 
zzynxSoftware engineerCommented:
try

         yourTabbedPane.setSelectedIndex(1);

followed by

         yourTabbedPane.getSelectedComponent().requestFocus();
0
 
zzynxSoftware engineerCommented:
>> 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
 
mmuruganandamCommented:
>> does not set focus to the tab

This where I got confused...
0
 
mmuruganandamCommented:
>>  how do i select the tab

This is one another to my confusion... :)
0
 
sharath_kulalAuthor Commented:
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
 
Nick_72Commented:
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
 
objectsCommented:
try:
TabbedPane.requestFocus();
0
 
sharath_kulalAuthor Commented:
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
 
zzynxSoftware engineerCommented:
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
 
objectsCommented:
didn't Nick72 already state that?
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
0
 
Nick_72Commented:
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
 
objectsCommented:
We'll all have to start 'asking' people to accept our comments :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now