• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tab order on swing components

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sir, friends

I have one doubt related to tab order. I have written a class that implements FocusTraversalPolicy. Now when my focus moves over the disabled component then getComponentAfter method of the FocusTraversalPolicy class is not getting called and hence next components doesnt receive any focus neither by pressing TAB nor by pressing SHIFT+TAB once the focus is on disabled component.

In case of enabled components everything works perfectly fine.

I need to move the tab/focus on the disabled components too.
Can anyone please help me in this regards ? Is it possible to set focus on disabled component although it doesnt makes sense to focus on disabled components ?

Waiting for your suggestions

Thanks and Regards
Rohit.
[ January 19, 2006: Message edited by: Rohit Bhagwat ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this skips the disabled components, if that is what you're after

needs additional code in
getDefaultComponent()
getFirstComponent()
getLastComponent()
if any are ever likely to be disabled.

and if firstComponent can be disabled,
int focusNumber = 0;
will need to be modified


 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how that's going to work Michael. Doesn't the number always get reset back to 0 since you're using %. Personally I use this algorithm I came up with:



It will skip components that are disabled and not focusable and will wrap around to the beginning. If it gets back to where it started it breaks and returns null to indicate there is no suitable component. I went on memory and didn't check the code very thoroughly so their may be a typo.

EDIT: Disabled smilies.
[ January 19, 2006: Message edited by: Ken Blair ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Doesn't the number always get reset back to 0 since you're using %

it does, but the if() on the following line checks whether focusList[0] is enabled
if not, componentAfter/Before is re-called and focusNumber becomes 1/(len-1)
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
> Doesn't the number always get reset back to 0 since you're using %

it does, but the if() on the following line checks whether focusList[0] is enabled
if not, componentAfter/Before is re-called and focusNumber becomes 1/(len-1)



So then it gets reset back to 0 again. This looks like an infinite loop.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it works on this
focusNumber = (focusNumber+1) % focusList.length;

where focusNumber is a class variable
if the % sets focusNumber to 0, and focusList[0] is disabled,
it loops and focusNumer becomes 1 etc
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the reply.

However my question is little bit different.
Actually the focus should go on next component no matter it is enabled or not. If the component is disabled still the focus should go on disabled component and should not skip the disabled component.
What I mean by this is pressing the tab should go on the disabled component however I should not show the line that appears around the component i.e I will not call requestFocus. The effect will be like you press the tab but you wonder where the focus is !!
Here's a sample example of what exactly should happen
1. Pressing tab moves the focus on enabled compoenent.
2. Again pressing the tab moves the focus on disabled component however I dont see any line around the disabled component so the effect is you dont know where the focus is.
3. Again pressing the tab moves the focus on enabled component.

The problem I am facing is once the focus is on disabled component then getComponentAfter method is not called.

Waiting for your replies..

Thanks and Regards
Rohit
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see if this gets you any closer to what you want.

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the reply.
Now I can see that the focus is on the disabled component and traversing is working in either direction but I should not be able to see the line which indicates that now the focus is on the diabled component.

Waiting for your reply

Thanks and Regards
Rohit
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create a method to loop through focusList, and if the component is an
instance of javax.swing.AbstractButton use setFocusPainted(boolean)
to set or remove the focus line.

call the method whenever you disable/re-enable a component.
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But then I understand that this method is only in AbstractButton. Actually I have other JComponents for which I require the same functionality.

Thanks and Regards
Rohit.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check the api docs for the other components, and look for the method that
handles the focus indication, and add code to handle this in the new method
mentioned in my previous reply.
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
check the api docs for the other components, and look for the method that
handles the focus indication, and add code to handle this in the new method
mentioned in my previous reply.



Thanks for your help Michael...You have helped me a lot..Thanks very much

Thanks and Regards
Rohit.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Michaael when I am using this class for the jtable then it is not working that i am not getting Focus out of the jtable to the next or previous component.
Thanks in advance for any help
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Syed Muhammad Mubashir Ahmed wrote:Dear Michaael when I am using this class for the jtable then it is not working that i am not getting Focus out of the jtable to the next or previous component.
Thanks in advance for any help


Syed, you already started a thread for this, and you haven't replied to my response posted there nearly an hour before you bumped this 6 year old thread.

Please go through UseOneThreadPerQuestion <- link
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When using Swing with the Netbeans designer, each "focusable" dialog control can set the "nextFocusableComponent" property (with no programming required).
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Doug Sorensen wrote:When using Swing with the Netbeans designer, each "focusable" dialog control can set the "nextFocusableComponent" property (with no programming required).



Maybe so, but using a visual designer / code generator without understanding the code it produces isn't a good idea at all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic