问题
I have a JPanel which is contained within a JScrollPane. The JPanel has components added to it's NORTH, CENTER, WEST and SOUTH areas (BorderLayout).
When I add a JTextPane to the SOUTH position, the scroll pane scrolls to show the text. I do not want the scroll pane to move from its topmost position. How can I prevent this?
回答1:
Absent more details, you can try setting the default caret to NEVER_UPDATE, available since Java 5.
JTextPane jtp = new JTextPane();
DefaultCaret caret = (DefaultCaret) jtp.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
来源:https://stackoverflow.com/questions/11299311/adding-a-jtextpane-to-borderlayout-south-causes-jscrollpane-to-scroll