簡體   English   中英

SWT文本輸出和換行

[英]SWT text output and new lines

我有一個程序正在用作習慣於GUI的實驗。 它基本上采用f(x)= ax ^ 2 + bx + c形式的二次項,並找到實零點,y軸截距和對稱軸。它在計算和所有方面都可以很好地工作。 我的問題是,我創建了一個不可編輯的文本框(使用窗口構建器SWT應用程序),無論我做什么,它總是將所有內容打印在一行上! \\ n不起作用,\\ r \\ n不起作用...請幫助。

Button btnNewButton = new Button(shlParacalc, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {

        String aval = alphabox.getText();
        double a = Double.parseDouble(aval);

        String bval = betabox.getText();
        double b = Double.parseDouble(bval);

        String cval = gammabox.getText();
        double c = Double.parseDouble(cval);


        CalcLib mathObj = new CalcLib();    

        double yint = mathObj.yIntercept(a, b, c);
        double axis = mathObj.Axis(a, b);
        double zero[] = mathObj.Zero(a, b, c);


        outputbox.append("y-intercept = " + yint); // these four lines need
        outputbox.append("axis of symmetry = " + axis); //to be printed
        outputbox.append("1st zero = " + zero[0]); //on individual lines
        outputbox.append("2nd zero = " + zero[1]);

您可能使用了錯誤的樣式位 此代碼有效:

public static void main(String[] args)
{
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);

    Button button = new Button(shell, SWT.NONE);
    button.setText("Add text");
    button.addListener(SWT.Selection, new Listener()
    {
        @Override
        public void handleEvent(Event e)
        {

            text.append("y-intercept = \n");
            text.append("axis of symmetry = \n");
            text.append("1st zero = \n");
            text.append("2nd zero = \n");
        }
    });

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

暫無
暫無

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

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