Reputation: 884
Is it possible to make a JTextArea
in a way that when the user starts to type when the program is launched it's it automatically starts to type in that JTextArea. Normally the the user first has to click on the JTextArea to start to type in it?
Can I make it that the user does not have to click a JTextArea to start typing it?
EDIT: I've tried using:
textField.requestFocusInWindow();
inside my frame class but that doesn't work.
Upvotes: 0
Views: 43
Reputation: 373
This called to gain focus and is configurable with your code. There are some samples which use Listeners to change JTextArea
at the proper time.
Method .requestFocusInWindow();
might fix your problem in the code bellow:
tabbedPane.addChangeListener(e -> {
Component comp = tabbedPane.getSelectedComponent();
if (comp.equals(pnlFoo)) {
txtFoo.requestFocusInWindow();
} else if (comp.equals(pnlBar)) {
txtBar.requestFocusInWindow();
}
});
Similar issue : Java - how do I gain focus on JTextArea when selecting a new JTabbedPane
This could help for your first run :
frame.addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
textArea_1.requestFocusInWindow();
Upvotes: 1