Solved

selecting tab and enabling selection border.

Posted on 2004-04-14
16
295 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 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