3

Can I have different foreground colors in one text area? Different fonts?

I want to add something like "hh:mm:ss Nickname: message", with time being gray, name - blue, message - black.

desudesudesu
  • 2,185
  • 1
  • 15
  • 20
  • it is certainly possible to do what you want using Swing JTextArea. I do not remember now what `(seesaw.core/text)` uses by default and whether seesaw supports rich text at all though. I may be able to answer later. – Vladimir Matveev Jan 22 '13 at 14:55
  • @VladimirMatveev it's fine if it's not clear seesaw solution(because, I guess it's not). I need the ability to append those colored messages to the end of already existing messages. – desudesudesu Jan 22 '13 at 15:17

2 Answers2

3

I made a mistake in my comment: it is JTextPane what you want, not JTextArea.

It turns out that seesaw supports JTextPane. See (seesaw.core/styled-text), which creates JTextPanes, and (seesaw.core/style-text!) which applies different styles to the text inside the pane.
Their usage seems to be pretty straightforward: first you define mapping id -> style during pane construction, and then you use this id when you assign styles to parts of the text.

Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
  • Thanks. I found this http://stackoverflow.com/questions/4059198/jtextpane-appending-a-new-string useful to append, because changing text directly removes styles. – desudesudesu Jan 22 '13 at 21:38
0

Textarea is a standard HTML element and it cannot take more styles. One way to acheive this is to use an iFrame and style the contents inside the iFrame. Otherway to achieve without iFrame is choose an editor that supports this features. One such editor is WMD which is used in stackoverflow. WMD files are here

Raja Asthana
  • 2,080
  • 2
  • 19
  • 35