Question

I have a Groovy app which uses a scrollPane built via swing builder:

BinsicWindow(def controller)
{
    controlObject = controller
    swinger = new SwingBuilder()
    mainFrame = swinger.frame(
        title: "Binsic is not Sinclair Instruction Code",
        size:[640, 480],
        show:true,
        defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE){
        scrollPane(autoscrolls:true) {
            screenZX = textArea(rows:24, columns:32) {visble:true}
        }
        screenZX.setFont(new Font("Monospaced", Font.PLAIN, 18))
    }
}

I add text to the textArea programatically (i.e. no user input) and I would like the textArea to scroll down automatically as content is added. But the view remains fixed at the top and I can only see the bottom (once the screen is more than full) by dragging the mouse.

Can I fix this? I have been searching for an answer to this for a wee while now and getting nowhere. Apologies if it's a simple answer.

Was it helpful?

Solution

The following lines should scroll your textarea to the last text position:

rect = screenZX.modelToView(screenZX.getDocument().getLength() - 1);
screenZX.scrollRectToVisible(rect);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top