• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

unexpeted focus transfer

 
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 3324
32
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob i changed all my requestFocus() to requestFocusInWindow() and it now works perfectly

thankyou
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic