Rob Bamforth's Blog
Java, SQL,T-SQL, MySQL, Networking, SQL Server, PHP, COM, DBA, ODBC

Posts Tagged ‘scroll’

JAVA – Set The Position Of The ScrollBar In JScrollPane()

June 4, 2009

The following codes assumes that you have created a JScrollPane() called scrollPane

int x = 0;
int y = 10;
scrollPane.getViewport().setViewPosition(new java.awt.Point(x, y));

In this example x sets the horizontal position of a horizontal scroll bar.
y sets the vertical position of a vertical scroll bar – in this case the vertical scroll bar will appear 10 pixels down from [...]

JAVA – Forca a JTextArea (text area) to the screoll to the bottom

April 1, 2009

You can force the JTextArea (text area) to scroll to the bottom by moving the caret to the end of the text area after the call to append:
textarea.append(“Some Text\n”);
textarea.setCaretPosition(textarea.getDocument().getLength());