简体   繁体   中英

vertical scroll bar doesn't appear until i resize the window - ScrolledFormText - Java

I created a ScrolledFormText containing a FormText using java and SWT. The problem is that when the window containig this ScrolledFormText opens and i start filling it with text until the text passes the end of the ScrolledFormText a scrollbar doesn't appear although it should, if i resize the window by dragging its edge to make it bigger or even smaller the scroll bar then appears. I would like to know if there is a solution for this problem so that i don't need to resize the window to make the scroll bar appear.

Here is the code responsible of creating the ScrolledFormText in the function:

    ScrolledFormText scrolledFormText = new ScrolledFormText(mform.getForm().getBody(), false);
    richtextPreview = mform.getToolkit().createFormText(scrolledFormText, false);
    scrolledFormText.setFormText(richtextPreview);
    mform.getToolkit().adapt(scrolledFormText);

    GridData gd_richtextPreview = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_richtextPreview.heightHint = 70;
    scrolledFormText.setLayoutData(gd_richtextPreview);
    mform.getToolkit().paintBordersFor(scrolledFormText);

    mform.getToolkit().paintBordersFor(richtextPreview);
    richtextPreview.setColor("header", this.getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
    richtextPreview.setColor("error", this.getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    richtextPreview.setFont("bold", SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));

And here is the part that sets the text in FormText:

    richtextPreview.setText(buf.toString(), true, true);
    richtextPreview.pack();

Experienced exactly the same problem and

scrolledFormText.reflow(false);

after setting the text is the way to go. Will not help OP anymore, but might be useful for others.

Try something like:

scroller = new JScrollPane(favoriteColors,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM