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

33
LINES

< > BotCompany Repo | #1000815 // Buggy LogView (Swing insertString bug)

JavaX fragment (include)

1  
static class LogView extends JScrollPane {
2  
  JTextPane textPane;
3  
4  
  *() {
5  
    textPane = new JTextPane();
6  
    textPane.setEditable(false);
7  
    setViewportView(textPane);
8  
  }
9  
10  
  // thread safe
11  
  public void logText(final String text) {
12  
    awt {
13  
      System.out.println("printing");
14  
      Document document = textPane.getDocument();
15  
      System.out.println("inserting");
16  
      document.insertString(document.getLength(), text, null);
17  
      System.out.println("done printing");
18  
19  
      // todo: scroll?
20  
    }
21  
  }
22  
23  
  // log some pure text and add a line feed
24  
  // thread safe
25  
  public void println(String line) {
26  
    logText(line + "\n");
27  
  }
28  
  
29  
  // thread safe
30  
  public void clear() {
31  
    awt { textPane.setText(""); }
32  
  }
33  
}

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: #1000815
Snippet name: Buggy LogView (Swing insertString bug)
Eternal ID of this version: #1000815/1
Text MD5: b8780ac726e165fed9bafff008b65258
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-28 20:23:24
Source code size: 756 bytes / 33 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 635 / 1024
Referenced in: [show references]