I am working on a barcode application which has in its main GUI a tabbed pane that contains many panels where one of this panels is for the cashier, the problem is that when the cashier panel is displayed i need to always set focus on the textfield where the barcode must be inserted.
requestFocusInWindow()
or requestFocus()
does not work since I am in the same jframe
and in the same jTabbedPane
but i am choosing panels inside this tabbedpane
what i need is when i move to a specific panel which is "cashier panel" is always to set focus on a certain textfield
thanks.
Asked
Active
Viewed 403 times
0

Inzimam Tariq IT
- 6,548
- 8
- 42
- 69

Hsein
- 11
- 6
-
possible duplicate of [How do you set a focus on Textfield in Swing?](http://stackoverflow.com/questions/1425392/how-do-you-set-a-focus-on-textfield-in-swing) – Madhawa Priyashantha Sep 16 '15 at 07:56
-
i tried this but when i choose another panel then go back to the desired panel which is cashier panel there is no focus on the textfeild that i need. – Hsein Sep 16 '15 at 08:00
-
hmmm add `addChangeListener` to your tabbedpane .then when tab selected/change check if active panel is cashier.if panel is cachier then call `requestFocus()` – Madhawa Priyashantha Sep 16 '15 at 08:06
-
can you explain more please? – Hsein Sep 16 '15 at 08:11
-
can you post a image of your gui with cashier panel ? – Madhawa Priyashantha Sep 16 '15 at 08:15
-
i need 10 reputation to post an image "stackoverflow conditions" – Hsein Sep 16 '15 at 08:26
-
use imgurl and give the link.also you can post your codes – Madhawa Priyashantha Sep 16 '15 at 08:27
-
thanks for your help the code below solves the problem – Hsein Sep 16 '15 at 08:35
2 Answers
1
private void MainTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {
if(CashierPanel.isShowing()){
Barcode_txt.requestFocus();
}
}

Madhawa Priyashantha
- 9,633
- 7
- 33
- 60

Hsein
- 11
- 6
0
This may also work,
when you specifying barcodeText's properties i.e. Height,Width etc set also focusable true
as
barcodeText.setFocusable(true);

Inzimam Tariq IT
- 6,548
- 8
- 42
- 69