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

41
LINES

< > BotCompany Repo | #1015529 // infoBox_centeredText

JavaX fragment (include)

1  
please include function infoMessage.
2  
3  
static JWindow infoBox_centeredText(S text) {
4  
  ret infoBox_centeredText(text, infoMessage_defaultTime);
5  
}
6  
7  
static JWindow infoBox_centeredText(final S text, final double seconds) {
8  
  print(text);
9  
  ret infoMessage_noprint(text, seconds);
10  
}
11  
12  
static JWindow infoBox_centeredText_noprint(S text) {
13  
  ret infoBox_centeredText_noprint(text, infoMessage_defaultTime);
14  
}
15  
16  
static JWindow infoBox_centeredText_noprint(final S text, final double seconds) {
17  
  if (empty(text)) null;
18  
  logQuotedWithDate(infoBoxesLogFile(), text); 
19  
  if (isHeadless()) null;
20  
  ret (JWindow) swingAndWait(func {
21  
    JWindow window = makeWindow(infoBox_centeredText_makePanel(text));
22  
    window.setSize(300, 150);
23  
    moveToTopRightCorner(window);
24  
    if (infoMessage_alwaysOnTop)
25  
      window.setAlwaysOnTop(true);
26  
    window.setVisible(true);
27  
    disposeWindowAfter(iround(seconds*1000), window);
28  
    ret window;
29  
  });
30  
}
31  
32  
static JPanel infoBox_centeredText_makePanel(S text) {
33  
  final JTextPane ta = jcenteredtextpane(text);
34  
  onClick(ta, r { disposeWindow(ta) });
35  
  int size = 14;
36  
  if (l(text) <= 50) size *= 2;
37  
  else if (l(text) < 100) size = iround(size*1.5);
38  
  ta.setFont(typeWriterFont(size));
39  
  JScrollPane sp = jscroll(ta);
40  
  ret withMargin(sp);
41  
}

Author comment

Began life as a copy of #1006245

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015529
Snippet name: infoBox_centeredText
Eternal ID of this version: #1015529/5
Text MD5: a9a629980743426f39a4c494249938e9
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-27 09:46:04
Source code size: 1306 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 435 / 453
Version history: 4 change(s)
Referenced in: [show references]