Problem with JTextArea autoscroll

D

DW

I'm having a problem with the autoscroll in a JTextArea.
My GUI simply contains:
1. A JTextArea within a JScrollPane
2. A JTextField
The JTextField has an action listener that appends the text from the
JTextField to the JTextArea. The autoscroll works fine until I hilight
some text from the JTextArea, copy it (ctrl-c) and paste it (ctrl-p)
into the JTextField. From that point on the autoscroll no longer
works.

Here's the relevent parts of my code:

jScrollPane = new javax.swing.JScrollPane();
jTextArea = new javax.swing.JTextArea();
jTextField = new javax.swing.JTextField();
jScrollPane.setViewportView(jTextArea);
jTextArea.setAutoscrolls(true);
....
jTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldActionPerformed(evt);
}
});
....
private void jTextFieldActionPerformed(java.awt.event.ActionEvent evt)
{
jTextArea.append(jTextField.getText() + "\n");
jTextField.setText("");
}


Do I need to have key listeners for CTRL-C and/or CTRL-P and manage
the copy/paste manually?

Any suggestions are appreciated.
 
H

hiwa

I'm having a problem with the autoscroll in a JTextArea.
My GUI simply contains:
1. A JTextArea within a JScrollPane
2. A JTextField
The JTextField has an action listener that appends the text from the
JTextField to the JTextArea. The autoscroll works fine until I hilight
some text from the JTextArea, copy it (ctrl-c) and paste it (ctrl-p)
into the JTextField. From that point on the autoscroll no longer
works.

Here's the relevent parts of my code:

jScrollPane = new javax.swing.JScrollPane();
jTextArea = new javax.swing.JTextArea();
jTextField = new javax.swing.JTextField();
jScrollPane.setViewportView(jTextArea);
jTextArea.setAutoscrolls(true);
...
jTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldActionPerformed(evt);
}
});
...
private void jTextFieldActionPerformed(java.awt.event.ActionEvent evt)
{
jTextArea.append(jTextField.getText() + "\n");
jTextField.setText("");
}


Do I need to have key listeners for CTRL-C and/or CTRL-P and manage
the copy/paste manually?

Any suggestions are appreciated.

Currently, who is handling Ctrl-C and Ctrl-P? Is the control
transfered to outside of Java?
 
C

Christian Kaufhold

DW said:
I'm having a problem with the autoscroll in a JTextArea.
My GUI simply contains:
1. A JTextArea within a JScrollPane
2. A JTextField
The JTextField has an action listener that appends the text from the
JTextField to the JTextArea. The autoscroll works fine until I hilight
some text from the JTextArea, copy it (ctrl-c) and paste it (ctrl-p)
into the JTextField. From that point on the autoscroll no longer
works.



FAQ. setCaretPosition.




Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top