You're forgetting that the JScrollPane has a border.
frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER);
Set it to null.
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(null);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
Another issue: this isn't Swing thread-safe:
public synchronized void run() {
try {
while (Thread.currentThread() == reader) {
try {
this.wait(100);
} catch (InterruptedException ie) {
}
if (pin.available() != 0) {
String input = this.readLine(pin);
textArea.append(input); // **************
}
if (quit)
return;
}
while (Thread.currentThread() == reader2) {
try {
this.wait(100);
} catch (InterruptedException ie) {
}
if (pin2.available() != 0) {
String input = this.readLine(pin2);
textArea.append(input); // **************
}
if (quit)
return;
}
} catch (Exception e) {
textArea.append("
Console reports an Internal error."); // **************
textArea.append("The error is: " + e); // **************
}
}
You're making textArea.append(...)
calls off of the Swing event thread, and this can cause hard to debug intermittent exceptions to be thrown. Be sure to only append to this text component on the event dispatch thread.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…