• Post Reply Bookmark Topic Watch Topic
  • New Topic

unexpeted focus transfer

 
peter m hayward
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using netbeans 8 windows xp pro

I have a number of textfields in the project and have set requestFocus() on each so that it tabs to the next one, this works fine. i then have a combobox again i have set the focus to the next textfield but before this can happen it jumps to the textArea, which is odd since the is no where in the code setting the focus to the textArea here is the code associated with the combobox



i have run though my code using the find facility in netbeans by putting the search item as requestFocus and the is no reference to textarea1 what so ever
anybody any ideas? how this can be happening

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a number of textfields in the project and have set requestFocus() on each so that it tabs to the next one,


I have no idea what this means. Nowhere in your code to you requestFocus(). By the way you should be using requestFocusInWindow().

In any case tabbing happens automatically. You don't do anything special to enable this. Basically it goes left to right and top to bottom.

i then have a combobox again...


Well in the code posted when you select an item from the combo box you make it invisible, which means focus needs to go somewhere. So I'm guessing Swing determines it needs to go to the text area. Use the requestFocusInWindow() method to have focus go where you want.

If you need more help then post a proper SSCCE that demonstrates the problem.



 
peter m hayward
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob i changed all my requestFocus() to requestFocusInWindow() and it now works perfectly

thankyou
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!