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

  • SEARCH
  • Home
  • 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 8656695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:20:28+00:00 2026-06-12T15:20:28+00:00

I have asked a very similar question, but I ended up using images instead

  • 0

I have asked a very similar question, but I ended up using images instead of changing the color.

I want all the text in the cells to be dark grey. I understand that you have to assign each column. But I do not how to do it.

This is one of my columns in my TableViewer.

col = new TableViewerColumn(this , SWT.NONE);
col.getColumn().setWidth(200);
col.getColumn().setText("Printer/Profile");
col.setLabelProvider(new ColumnLabelProvider() {
    @Override
    public String getText(Object element) {
        AplotResultsDataModel.ResultsData p = (AplotResultsDataModel.ResultsData) element;
        return p.getPrinterProfile();
    }
}); 

How would I change the above code to incorporate setting the font color to dark gray?

EDIT

If I am using the switch, how does it know how many columns I have?
also how do I set the column names? Here is how I have it set up right now

TableViewerColumn col = new TableViewerColumn(this , SWT.NONE);
  col.getColumn().setWidth(150);
  col.getColumn().setText("ItemId");
  col.setLabelProvider(new ColumnLabelProvider() {
     @Override
     public void update(ViewerCell cell)
     {
         Object element = cell.getElement();
         if(element instanceof AplotPDFDataModel.FileNameData)
         {
            AplotPDFDataModel.FileNameData p = (AplotPDFDataModel.FileNameData) element;
            cell.setForeground(ColorConstants.darkGray);
            switch(cell.getColumnIndex())
            {
               case 0:
                  try {
                     cell.setText(p.getRev().getStringProperty("item_id"));
                  }
                  catch (TCException e) {
                     e.printStackTrace();
                  }
                  break;
               case 1:
                  try {
                     cell.setText(p.getRev().getStringProperty("item_revision_id"));
                  }
                  catch (TCException e) {
                     e.printStackTrace();
                  }
                  break;
               case 2:
                  cell.setText(p.getPRLValue().toString());
                  break;
               case 3:
                  cell.setText(p.getMarkupValue());
                  break;
               case 4:
                  cell.setText(p.getFileName());
                  break;
             }
         }
     }
 });
  • 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-12T15:20:29+00:00Added an answer on June 12, 2026 at 3:20 pm

    I would use the method update(ViewerCell cell) of the ColumnLabelProvider instead of getText(). Then you can call ViewerCell#setForeground(Color color):

    public class ColorColumnLabelProvider extends ColumnLabelProvider {
        @Override
        public void update(ViewerCell cell)
        {
            Object element = cell.getElement();
            if(element instanceof AplotResultsDataModel.ResultsData)
            {
                AplotResultsDataModel.ResultsData p = (AplotResultsDataModel.ResultsData) element;
    
                cell.setForeground(YOUR_COLOR);
                switch(cell.getColumnIndex())
                {
                    case 0:
                        cell.setText(p.YOUR_FIRST_TEXT);
                        break;
                    case 1:
                        cell.setText(p.YOUR_SECOND_TEXT);
                        break;
                    case ...
                }
            }
        }
    }
    

    Then use:

    col.getColumn().setWidth(150);
    col.getColumn().setText("ItemId");
    col.setLabelProvider(new ColorColumnLabelProvider());
    

    Since I switch the column index, you can use this ColorColumnLabelProvider for all your columns.

    Don’t forget to dispose the color somewhere.

    If you use ColorConstants of Draw2d, you don’t need to dispose them.

    In your case ColorConstants.darkGray would do the job.

    ALTERNATIVE:

    You can also define a ColumnLabelProvider that implements IColorProvider:

    public class ColorColumnLabelProvider extends ColumnLabelProvider implements IColorProvider {
    
        @Override
        public Color getBackground(Object element) {
            return null;
        }
    
        @Override
        public Color getForeground(Object element) {
            return YOUR_COLOR;
        }
    
        @Override
        public String getText(Object element) {
            AplotResultsDataModel.ResultsData p = (AplotResultsDataModel.ResultsData) element;
            return p.getPrinterProfile();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked a similar question before, but didn't get very good results. I've
I've already asked a very similar question but that was using javascript/php - i've
I know that similar questions have been asked before, but I am very much
Possible Duplicate: Notification when WPF UI closes I have asked a very similar question
I've asked very similar question before and should have mentioned more detailed. Last time
This is very similar to a question I asked the other day but my
This is very similar to a question I asked the other day but my
This is a follow up to a very similar question I have already asked
I asked a similar question a while ago but I didn't know very much,
I'd asked a very similar question earlier , but the project scope is quickly

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.