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

22
LINES

< > BotCompany Repo | #1033722 // componentShowingVar - a variable that always indicates if a component is showing (so you can query this without going to Swing thread)

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

Libraryless. Click here for Pure Java version (4740L/26K).

1  
static BoolVar componentShowingVar(JComponent component) {
2  
  ret swing(-> {
3  
    BoolVar flag = new(component.isShowing());
4  
    
5  
    component.addAncestorListener(new AncestorListener {
6  
      public void ancestorAdded(AncestorEvent event) {
7  
        if (flag!) print("Warning: bindToComponent logic failure");
8  
        flag.set(true);
9  
      }
10  
  
11  
      public void ancestorRemoved(AncestorEvent event) {
12  
        if (!flag!) print("Warning: bindToComponent logic failure");
13  
        flag.set(false);
14  
      }
15  
  
16  
      public void ancestorMoved(AncestorEvent event) {
17  
      }
18  
    });
19  
    
20  
    ret flag;
21  
  });
22  
}

Author comment

Began life as a copy of #1003557

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033722
Snippet name: componentShowingVar - a variable that always indicates if a component is showing (so you can query this without going to Swing thread)
Eternal ID of this version: #1033722/2
Text MD5: 87d73114aed138ac9158420e23f43f56
Transpilation MD5: e7d0adb757b731ff3a9d38e08ed3c625
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-30 18:59:28
Source code size: 623 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 89 / 143
Version history: 1 change(s)
Referenced in: [show references]