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

27
LINES

< > BotCompany Repo | #1001521 // Swing: Test Courier font & two colors

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (86L/1K/4K).

1  
!747
2  
3  
m {
4  
  p {
5  
    JFrame jf = new JFrame("Courier?");
6  
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
7  
    Container cp = jf.getContentPane();
8  
9  
    JTextPane pane = new JTextPane();
10  
    
11  
    appendToTextPane(pane, Color.green, "Hello! \n");
12  
    appendToTextPane(pane, Color.blue, "World :)\n");
13  
    
14  
    cp.add(new JScrollPane(pane), BorderLayout.CENTER);
15  
16  
    jf.setSize(400, 300);
17  
    jf.setVisible(true);
18  
  }
19  
  
20  
  static void appendToTextPane(JTextPane pane, Color color, S text) ctex {
21  
    Document doc = pane.getStyledDocument();
22  
    SimpleAttributeSet set = new SimpleAttributeSet();
23  
    StyleConstants.setFontFamily(set, "Courier");
24  
    StyleConstants.setBackground(set, color);
25  
    doc.insertString(doc.getLength(), text, set);
26  
  }
27  
}

Author comment

Began life as a copy of #1000992

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
1134 stefan OK but too small and should be bold 2015-10-21 20:17:02

add comment

Snippet ID: #1001521
Snippet name: Swing: Test Courier font & two colors
Eternal ID of this version: #1001521/1
Text MD5: ee878481d4ed88a05ac9b668d0d0a2ea
Transpilation MD5: 36a76db3784c5f048fa15c096201d407
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-21 20:16:17
Source code size: 775 bytes / 27 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 878 / 847
Referenced in: [show references]