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

!747

m {
  p {
    JFrame jf = new JFrame("Courier?");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = jf.getContentPane();

    JTextPane pane = new JTextPane();
    
    appendToTextPane(pane, Color.green, "Hello! \n");
    appendToTextPane(pane, Color.blue, "World :)\n");
    
    cp.add(new JScrollPane(pane), BorderLayout.CENTER);

    jf.setSize(400, 300);
    jf.setVisible(true);
  }
  
  static void appendToTextPane(JTextPane pane, Color color, S text) ctex {
    Document doc = pane.getStyledDocument();
    SimpleAttributeSet set = new SimpleAttributeSet();
    StyleConstants.setFontFamily(set, "Courier");
    StyleConstants.setBackground(set, color);
    doc.insertString(doc.getLength(), text, set);
  }
}

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: 962 / 950
Referenced in: [show references]