Libraryless. Click here for Pure Java version (7970L/45K).
1 | svoid scrollToCenter(JScrollPane sp) { |
2 | if (sp == null) ret; |
3 | swing { |
4 | var viewPort = sp.getViewport(); |
5 | Dimension viewSize = viewPort.getExtentSize(); |
6 | Dimension contentSize = viewPort.getViewSize(); |
7 | int x = max(0, contentSize.width-viewSize.width)/2; |
8 | int y = max(0, contentSize.height-viewSize.height)/2; |
9 | viewPort.setViewPosition(new Point(x, y)); |
10 | } |
11 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035474 |
Snippet name: | scrollToCenter |
Eternal ID of this version: | #1035474/1 |
Text MD5: | 055894f83e2d29c8d5d57c61b33a1a92 |
Transpilation MD5: | 15d6293c5dbec3eda04ec492c6a48c42 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-22 21:05:47 |
Source code size: | 388 bytes / 11 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 101 / 144 |
Referenced in: | [show references] |