Solved

selecting tab and enabling selection border.

Posted on 2004-04-14
16
274 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now