来自Text小部件的SWT getText()返回NULL字符串

时间:2013-02-23 00:41:39

标签: java eclipse events swt listener

此SWT程序有一个名为mBuy的组,其中包含输入股票买入价格的文本字段。按下计算按钮并激活事件监听器后,我想将此文本字段内的任何内容分配给变量,我已在此处初始化。

final Text tmp0 = new Text(mBuy, SWT.SINGLE);
tmp0.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

// Calculate Button
Button tmp3 = new Button(mBuy, SWT.PUSH);
tmp3.setText("Calculate");
tmp3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));

// if calculate button is pressed
tmp3.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
        //take the decimal value inside textbox 
        bPrice=Double.parseDouble(tmp0.getText());
        // don't show buy menu anymore
        mBuy.dispose();

    }
});

0 个答案:

没有答案