Beispiel #1
0
 public void append(Color c, String s) {
   StyleContext sc = StyleContext.getDefaultStyleContext();
   AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
   int len = getDocument().getLength();
   setCaretPosition(len);
   setCharacterAttributes(aset, false);
   replaceSelection(s);
 }
Beispiel #2
0
 public ConsolePanel() {
   super(new BorderLayout());
   text.setFont(StyleContext.getDefaultStyleContext().getFont("SansSerif", Font.PLAIN, 10));
   JScrollPane scroller = new JScrollPane(text);
   scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
   add(BorderLayout.CENTER, scroller);
 }
  void finishInit() {
    // Create 3 styles associated with the text panes
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style regular0 = jTextPane.addStyle("regular", def);
    Style regular1 = commentPane.addStyle("regular", def);

    Style s0 = jTextPane.addStyle("old", regular0);
    Style s1 = commentPane.addStyle("old", regular1);
    StyleConstants.setBackground(s0, Color.yellow);
    StyleConstants.setBackground(s1, Color.yellow);

    s0 = jTextPane.addStyle("new", regular0);
    StyleConstants.setBackground(s0, Color.pink);
    s1 = commentPane.addStyle("new", regular1);
    StyleConstants.setBackground(s1, Color.pink);
  }