Archive for January, 2009

Java: Scrolling a JScrollPane (JEditorPane) to the bottom

Recently, I’ve stumbled upon a difficult issue in Java. If you’ve got a JEditorPane contained in a JScrollPane, and you add text to the JEditorPane and then, on the next line, try to scroll the JEditorPane to the bottom, you’ll still end up with the scroll bar at the top. The reason is quite simple: Threading. When you call JEditorPane.setText(), you cause Java to do some stuff behind the scenes in a different thread — not the main thread. When you then try to set the scroll position on the next line, the scroll bar position will change — however, Java’s behind the scenes thread will move it back to the top — pretty standard concurrency bug. Anyway, there is a simple fix:

private void scrollPaneToBottom() {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

jScrollPane1.getVerticalScrollBar().setValue(

jScrollPane1.getVerticalScrollBar().getMaximum());

}

});

}

SwingUtilities.invokeLater runs a Runnable (which is pretty much a thread, for this extent and purpose.) after all of Java's behind-the-scenes stuff finishes.

Comments (4)

Price… you’re doing it wrong!

Burger King…
Price.. youre doing it wrong!

Leave a Comment

Mumble, a free (as in speech) TeamSpeak/Vent alternative

For the past couple of weeks, I’ve been using Mumble to replace a TeamSpeak server one of my friends was paying for. We’re all quite pleased with the results.

Server installtion could not be easier. If you’ve got an Ubuntu server, you can simply install the ‘mumble-server’ package and change a couple of configuration files, you’ll be up and running in no time.

The client side interface is really where Mumble shines. For the first time ever, configuring an audio application on Linux was as simple and painless as it was on Windows and Mac. The voice activation features were more advanced then I’ve ever seen — not just a simple threshold. Echo cancelation seems to be done incredibly well too.

All in all, a very good, very solid application… give it a shot: http://mumble.sourceforge.net/Main_Page

Leave a Comment