SWT StyledText draw box

73 views Asked by At

I'm trying to draw a box in a StyledText widget to surround my text. I'm using the following code and failing. I know it can be done because of samples I have found that I tried and worked. What am I missing?

public void print(Display display) {

    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setSize(500, 500);

    StyledText st=new StyledText(shell,SWT.BORDER);
    shell.open();

    //line one
    String one=String.format("Character Name: %-25s   Player Name: ___________________________\n",WordUtils.capitalize(name));

    st.setText(one);
    Point topLeft=st.getLocationAtOffset(0);
    GC gc=new GC(st.getShell());
    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
    gc.drawRectangle(topLeft.x - 1, topLeft.y, 20, 15);
    gc.dispose();

}
0

There are 0 answers