J
Jason Cavett
Hello,
I am trying to write a text field so that when the text in the
JTextField is updated, the title bar of the main window updates with
it. However, I am having a problem. I register my listener below:
projectNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent e) {
frame.setTitle(projectNameTextField.getText());
}
});
The problem is that the title is always one character behind what I
have typed. Like this...
Project Name: Project
Title Bar: Project
Project Name: Projec
Title Bar: Project
Project Name: Proje
Title Bar: Projec
I tried other listeners (such as the CaretListener) but that updates
too soon (do to something else I'm doing - I don't want the title bar
to update just because I clicked in the title bar box). From what I
can tell the problem that I'm having is that I'm getting the text in
the JTextField before the event has finished firing which is why the
text hasn't been updated at that point. Is there a better approach to
what I am doing?
Thanks
I am trying to write a text field so that when the text in the
JTextField is updated, the title bar of the main window updates with
it. However, I am having a problem. I register my listener below:
projectNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent e) {
frame.setTitle(projectNameTextField.getText());
}
});
The problem is that the title is always one character behind what I
have typed. Like this...
Project Name: Project
Title Bar: Project
Project Name: Projec
Title Bar: Project
Project Name: Proje
Title Bar: Projec
I tried other listeners (such as the CaretListener) but that updates
too soon (do to something else I'm doing - I don't want the title bar
to update just because I clicked in the title bar box). From what I
can tell the problem that I'm having is that I'm getting the text in
the JTextField before the event has finished firing which is why the
text hasn't been updated at that point. Is there a better approach to
what I am doing?
Thanks