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

25
LINES

< > BotCompany Repo | #1023014 // screenTextOverlay - single row only, doesn't hide automatically

JavaX fragment (include)

1  
import java.awt.font.*;
2  
import java.awt.geom.*;
3  
4  
static JWindow screenTextOverlay(fS text, O... _) {
5  
  ret swing(func -> JWindow {
6  
    JPanel panel = singleColorPanel(optPar color(_, Color.WHITE));
7  
    new JWindow w;
8  
    w.add(panel);
9  
    w.setAlwaysOnTop(true);
10  
    w.setVisible(true);
11  
12  
    Font font = cast optPar font(_);
13  
    if (font == null)
14  
      font = w.getFont().deriveFont(boolPar bold(_) ? Font.BOLD : Font.PLAIN, optPar fontSize(_, 80));
15  
    TextLayout tl = new TextLayout(text, font,
16  
      ((Graphics2D) w.getGraphics()).getFontRenderContext());
17  
    Rectangle2D r = tl.getBounds();
18  
    new AffineTransform tx;
19  
    tx.translate(0, r.getHeight());
20  
    Shape outline = tl.getOutline(tx);
21  
    centerWindow(w, iceil(r.getWidth()), iceil(r.getHeight()));
22  
    w.setShape(outline);
23  
    ret w;
24  
  });
25  
}

Author comment

Began life as a copy of #1013349

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023014
Snippet name: screenTextOverlay - single row only, doesn't hide automatically
Eternal ID of this version: #1023014/5
Text MD5: 5a28b279bd8964eb2702849721d26afe
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-20 20:12:50
Source code size: 829 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 265 / 310
Version history: 4 change(s)
Referenced in: [show references]