簡體   English   中英

直到我調整窗口大小,垂直滾動條才會出現-ScrolledFormText-Java

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

我使用Java和SWT創建了一個包含FormText的ScrolledFormText。 問題是,當窗口包含igigig窗口打開時,我開始用文本填充文本,直到文本通過ScrolledFormText的末尾,盡管應該,但滾動條不會出現,如果我通過拖動其邊緣來調整窗口大小以使其變大或什至更小的滾動條出現。 我想知道是否有解決此問題的方法,這樣我就不需要調整窗口大小來顯示滾動條。

這是負責在函數中創建ScrolledFormText的代碼:

    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));

這是在FormText中設置文本的部分:

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

經歷了完全一樣的問題,並且

scrolledFormText.reflow(false);

設置文本后是要走的路。 不再對OP有所幫助,但可能對其他人有用。

嘗試類似:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM