Solved

selecting tab and enabling selection border.

Posted on 2004-04-14
16
302 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
map related example 6 55
maven disable workspace resolution 1 21
Java Eclipse Loop 3 20
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

839 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