debugging gui/event/threading problems

V

VisionSet

I have a swing applet that regularly does screwy things in the gui.
Text caret focus goes and can't be regained. messed up painting. This
is just simple JTextPanes and StyledDocuments. I have my own threads
that update the gui through calls to the documents, synchronising on
the document and calling invokeLater.

What is a good way to track down problems such as these?

Is there anything wrong with this method, called from a user thread?

private void appendInText(final String owner, final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Logger.log("appendInText(): " + owner + ", " + text);

final AttributeSet attributes;
if (user.equals(owner)) attributes = userAttr;
else if (recipient.equals(owner)) attributes = reciAttr;
else attributes = consAttr;

final StringBuffer builder = new StringBuffer();
builder.append(owner);
builder.append(": ");
synchronized(inDocument) { // explicitly thread safe
final int length = inDocument.getLength(); //
StyledDocument
if (length != 0) builder.insert(0, '\n');
try {
inDocument.insertString(length, builder.toString(),
consAttr);
inDocument.insertString(
length + builder.length(), text, attributes);
}
catch(BadLocationException ex) {
Logger.log(ex);
}
}
}
});
}

TIA ,
Mike W
 

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

Similar Threads


Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top