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 8601679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:54:00+00:00 2026-06-12T01:54:00+00:00

So I have a problem, when I add an image to any column of

  • 0

So I have a problem, when I add an image to any column of a JFace table the first column also behaves like it has an image in and the text is indented by the size of that image.

Here’s a screenshot illustrating my point with the code needed to produce it. Is there anyway to stop this from happening because it’s really getting on my wick?

Regards,

Glen x

enter image description here

package widgets;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

public class ComponentTest {

    private static Image image;

    public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, true));

        TableViewer viewer1 = getViewer(shell, true);
        TableViewer viewer2 = getViewer(shell, false);

        List<String> rows = new ArrayList<String>();
        rows.add("Row 1");
        rows.add("Row 2");

        viewer1.setInput(rows);
        viewer2.setInput(rows);

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    private static TableViewer getViewer(final Shell shell, boolean addImage) {
        TableViewer viewer = new TableViewer(shell, SWT.FULL_SELECTION
                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NONE);

        viewer.setContentProvider(ArrayContentProvider.getInstance());

        viewer.getTable().setLayoutData(
                new GridData(SWT.FILL, SWT.FILL, true, true));

        TableViewerColumn col = new TableViewerColumn(viewer, SWT.NONE);
        col.getColumn().setWidth(100);
        col.getColumn().setText("Text Column");
        col.setLabelProvider(new StyledCellLabelProvider() {
            @Override
            public void update(ViewerCell cell) {
                cell.setText((String) cell.getElement());
            }
        });

        col = new TableViewerColumn(viewer, SWT.NONE);
        col.getColumn().setWidth(100);
        col.getColumn().setText("Second Text Column");
        col.setLabelProvider(new StyledCellLabelProvider() {
            @Override
            public void update(ViewerCell cell) {
                cell.setText((String) cell.getElement());
            }
        });

        if (addImage) {
            col = new TableViewerColumn(viewer, SWT.NONE);
            col.getColumn().setWidth(100);
            col.getColumn().setText("Image Column");
            col.setLabelProvider(new StyledCellLabelProvider() {
                @Override
                public void update(ViewerCell cell) {
                    cell.setImage(getImage(shell.getDisplay()));
                }
            });
        }
        viewer.getTable().setHeaderVisible(true);

        return viewer;
    }

    // make a little green square
    private static Image getImage(Display display) {
        if (image == null) {
            PaletteData palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
            ImageData imageData = new ImageData(16, 16, 24, palette);

            for (int x = 0; x < 16; x++) {
                for (int y = 0; y < 16; y++) {
                    imageData.setPixel(x, y, 0xFF00);
                }
            }
            ;
            image = new Image(display, imageData);
        }
        return image;
    }
}
  • 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-12T01:54:01+00:00Added an answer on June 12, 2026 at 1:54 am

    That is a quite annoying bug when using Windows. You can use a dirty fix by skipping the first column (not using it) and setting its width to zero.

    As far as I remember correctly, this will introduce some minor glitches when using MacOS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem, I have tried different solutions to add a image
I have a problem with WPF Toolkit Chart Control. I can't add text values
I have an image list and would like to add a directory of images
Here's my problem. I have an mx:Image within an mx:DataGrid column. If I do
I have a problem that I'd like to add round mask on top of
I have problem to add jQuery to some existing code, please help. We have
I have a problem: I've add a Jquery UI drag-n-drop widget to my page,
I have problem, when I want add Node to my GUI from other Thread.
I have problem on my blog: http://osify.com while processing add new post with above
I have a problem where I have to add thirty-three integer vectors of equal

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.