Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:09:02+00:00 2026-06-02T15:09:02+00:00

I am new to Java and would like to know how to set the

  • 0

I am new to Java and would like to know how to set the font and font color to be used for the next text to be added to a SWT StyledText box.

So for example I have an application that defines “command” and “data” text and each is to be displayed in a different font/color. So let’s say I’ve just added some “command” text. Now how do I set things up so that the next text which will be “data” text is displayed in a different font and color?

I’ve done a lot of googling, but nothing seems to be helping me.

P.S.: This can’t be the most efficient way to do it:

int a = st.getCharCount();

Font font = new Font(shlProtruleModifier.getDisplay(), "Courier", 10, SWT.NORMAL);

StyleRange[] sr = new StyleRange[1];

sr[0] = new StyleRange();

st.append("\r\nWhat the heck?");

sr[0].start = a;
sr[0].length = st.getCharCount() - a;
sr[0].font = font;
sr[0].foreground = SWTResourceManager.getColor(SWT.COLOR_BLACK);

st.replaceStyleRanges(sr[0].start, sr[0].length, sr);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:09:03+00:00Added an answer on June 2, 2026 at 3:09 pm

    So all I’ve been able to come up with the following technique that does work,

    int a = st.getCharCount();
    
    Font font = new Font(shlProtruleModifier.getDisplay(), "Courier", 10, SWT.NORMAL);
    
    StyleRange[] sr = new StyleRange[1];
    
    sr[0] = new StyleRange();
    
    st.append("\r\nWhat the heck?");
    
    sr[0].start = a;
    sr[0].length = st.getCharCount() - a;
    sr[0].font = font;
    sr[0].foreground = SWTResourceManager.getColor(SWT.COLOR_BLACK);
    
    st.replaceStyleRanges(sr[0].start, sr[0].length, sr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new to java, and would like some advice on the following i
I am new to Java, the function I would like to perform is to
I would like to know if this is possible in java that i want
I would like to know the what type of concept is used in the
I'm relatively new to Java and would appreciate any help on this! I have
I would like to know the recommended library or procedure for dealing with multi-coloured
I would like to know a way to actually make the status bar that
I have some TODO tags in my Java code and would like to parameterize
I have just set up a new Eclipse Java project. In this project I
I am new to Java world but I am pretty good at using Flex,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.