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).

static BoolVar componentShowingVar(JComponent component) {
  ret swing(-> {
    BoolVar flag = new(component.isShowing());
    
    component.addAncestorListener(new AncestorListener {
      public void ancestorAdded(AncestorEvent event) {
        if (flag!) print("Warning: bindToComponent logic failure");
        flag.set(true);
      }
  
      public void ancestorRemoved(AncestorEvent event) {
        if (!flag!) print("Warning: bindToComponent logic failure");
        flag.set(false);
      }
  
      public void ancestorMoved(AncestorEvent event) {
      }
    });
    
    ret flag;
  });
}

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: 86 / 138
Version history: 1 change(s)
Referenced in: [show references]