Setting the focus to a text field

前端 未结 9 1781
日久生厌
日久生厌 2020-12-16 14:50

I have an application developed in netbeans and I want to set the focus to a certain jTextField when a panel is displayed. I have read a number of post and have

9条回答
  •  一向
    一向 (楼主)
    2020-12-16 15:15

    For me the easiest way to get it to work, is to put the component.requestFocus(); line, after the setVisible(true); line, at the bottom of your frame or panel constructor.

    This probably has something to do with asking for the focus, after all components have been created, because creating a new component, after asking for the focus request, will make your component loose te focus, and make the focus go to your newly created component. At least, that's what I assume.

提交回复
热议问题