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

20
LINES

< > BotCompany Repo | #1003516 // maximizeFrame - better in non-AWT thread (so it can wait for the maximization)

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

Libraryless. Click here for Pure Java version (2745L/18K).

1  
static <A extends Component> A maximizeFrame(A c) {
2  
  JFrame f = swing(func -> JFrame {
3  
    JFrame f = getFrame(c);
4  
    if (f != null)
5  
      f.setExtendedState(JFrame.MAXIMIZED_BOTH);
6  
    ret f;
7  
  });
8  
  
9  
  // wait until frame is actually maximized so
10  
  // we can add components based on correct size
11  
  if (f != null && !isAWTThread()) {
12  
    Dimension d = maximumWindowBounds().getSize();
13  
    long start = sysNow();
14  
    repeat with ms sleep 1 {
15  
      if (f.getWidth() >= d.getWidth()-100 && f.getHeight() >= d.getHeight()-100) break;
16  
      if (sysNow() >= start+100) { warn("maximizeFrame timeout"); break; }
17  
    }
18  
  }
19  
  ret c;
20  
}

Author comment

Began life as a copy of #1003513

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1003516
Snippet name: maximizeFrame - better in non-AWT thread (so it can wait for the maximization)
Eternal ID of this version: #1003516/11
Text MD5: a4f46de977d99e59fc669d8a71bd2209
Transpilation MD5: 801216af603530ee3f705dcbb618604a
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-14 17:37:13
Source code size: 649 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 595 / 686
Version history: 10 change(s)
Referenced in: [show references]