Results 1 to 2 of 2
  1. #1
    ourimaler is offline Member
    Join Date
    May 2010
    Rep Power

    Default Changing text color in SWT

    I've been checking online tutorials and Google for several days, but I can't seem to figure out the solution to this problem:
    I'm designing a GUI for a certain program using SWT and Eclipse. I've added a console (meaning, a Text object) for printing the program's output, which seems to work fine.
    However, I also wanted to add a warning() method, which would print red text in the console. Thing is...I have no idea how to set the color. The setForeground() method will change the color of all the text, whether or not it's a "warning".
    So, basically, I'm trying to code two different methods for inserting text in a console, with each method printing differently-colored text. Any suggestions?

    Relevant code snippets:
    Text console;

    console = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
    console.setLayoutData(new RowData(400, 600));

    public void output(String message){
    console.insert(message + "\n"); //this prints regular black text. Works fine.

    public void warning(String message){
    console.insert(message + "\n"); //this needs to print red text, somehow...

  2. #2
    Mariusz is offline Member
    Join Date
    Jun 2010
    Rep Power


    Instead of Text try to use StyledText and then use setStyleRange(StyleRange style)

Similar Threads

  1. text color
    By jpito in forum Advanced Java
    Replies: 1
    Last Post: 11-18-2009, 01:33 AM
  2. Changing println font color
    By xcallmejudasx in forum New To Java
    Replies: 4
    Last Post: 05-21-2009, 05:05 PM
  3. Color-changing model
    By higuchi in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 08:29 AM
  4. Changing color of variables view details
    By mtoledo in forum Eclipse
    Replies: 0
    Last Post: 03-25-2008, 03:35 PM
  5. Changing the color of text
    By Lang in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 10:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts