Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] is it a bug of StyledText 3.0 ?

Dear Irvine :
    I tryed the way you told me, but it still not work. I'm really confused:)
    please, once more help me !
    my code is here:


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
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 StyledTextTry {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, true));
        StyledText st = new StyledText(shell, SWT.WRAP);
        st.setText("aaaaabbbbbcccccdddddeeeeeaaaaabbbbbcccccdddddeeeee");
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.horizontalSpan = 1;
        gridData.grabExcessHorizontalSpace = true;
        st.setLayoutData(gridData);

        StyledText st2 = new StyledText(shell, SWT.WRAP);
        st2.setText("aaaaabbbbbcccccdddddeeeeeaaaaabbbbbcccccdddddeeeee");
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.horizontalSpan = 1;
        st.setLayoutData(gridData);

        shell.setSize(100, 200);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

}
 

the result is:






Veronika Irvine wrote:
You need to add the line:

gridData.grabExcessHorizontalSpace = true;

This will enable wrapping. 

The old StyledText.computeSize code was actually quite wrong because it 
based the height it returned on its current width and not on the width 
passed in as the wHint argument.  Therefore if you changed the width by 
only a small amount, it seemed to give the right answer but if you changed 
the width by a large amount, you got quite a wrong answer.




"yuhf" <yuhf@xxxxxxxxxxxxxxxx> 
Sent by: platform-swt-dev-admin@xxxxxxxxxxx
11/11/2004 03:14 AM
Please respond to
platform-swt-dev


To
<platform-swt-dev@xxxxxxxxxxx>
cc

Subject
[platform-swt-dev] is it a bug of StyledText 3.0 ?






Hi,
My StyledText works perfictly in SWT2.0, but in SWT3.0, it is alway
displayed in only one line,
even if the content is multi-line, the hight of the control is always
the same (12).
I figer out that StyledText.computeSize() has been modified from 2.0 to
3.0. If only replace this function with old code, it's OK.
I wonder it's a bug of SWT3.0.
my code is here:

Shell parent = getParent();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE);
shell.setLayout(new GridLayout(5, true));

st = new StyledText(shell, SWT.WRAP);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.horizontalSpan = 4;
st.setLayoutData(gridData);
st.setText("aaaaabbbbbcccccdddddeeeeeaaaaabbbbbcccccdddddeeeee");
shell.pack();
shell.open();
Display display = parent.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

thank you

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev

  


Back to the top