Question

I am developing an Eclipse plugin. I have a view in Eclipse which shows a string. The Problem is that the string is layouted different than in console/debug view in eclipse. The string separates the characters with spaces no tabs (\t) or anything. how can i achieve that the Label in my view is showing the string like the console?

Console/debug view: http://s14.directupload.net/images/140410/ebydtn3n.png

My Eclipse view with a Label: http://s1.directupload.net/images/140410/yccg36sn.png

my view class:

public class PacketDumpView extends ViewPart {


private Label dumpLabel=null;
private Composite parent;

@Override
public void createPartControl(Composite parent) {

    if(dumpLabel!=null)
        return;

    this.parent = parent;
    GridLayout layout = new GridLayout(1, true);
    parent.setLayout(layout);
}

@Override
public void setFocus() {
    // TODO Auto-generated method stub

}

public void setValues(String hexDump) {
    if(dumpLabel==null){
        dumpLabel = new Label(parent, SWT.NONE);
        dumpLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        dumpLabel.setText(hexDump);
    }
}
Was it helpful?

Solution

You probably need a mono-spaced font for your label. The Text font is usually mono-spaced, you can set that as the font for your label using:

Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT);

dumpLabel.setFont(font);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top