Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

11
LINES

< > BotCompany Repo | #1035474 // scrollToCenter

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7970L/45K).

svoid scrollToCenter(JScrollPane sp) {
  if (sp == null) ret;
  swing {
    var viewPort = sp.getViewport();
    Dimension viewSize = viewPort.getExtentSize();
    Dimension contentSize = viewPort.getViewSize();
    int x = max(0, contentSize.width-viewSize.width)/2;
    int y = max(0, contentSize.height-viewSize.height)/2;
    viewPort.setViewPosition(new Point(x, y));
  }
}

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: 100 / 142
Referenced in: [show references]