SWT文本小部件未显示

时间:2011-07-19 15:21:48

标签: java eclipse scala layout swt

package org.jilen.editor
import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Shell
import org.eclipse.swt.widgets.Text
import org.eclipse.swt.SWT

object EditorApp {
  def main(args: Array[String]) {
    val display = new Display()
    val shell = new Shell(display)
    val text = new Text(shell, SWT.CENTER)
    text.setText("Hello SWT")
    shell.pack()
    shell.open()
    while (!shell.isDisposed) {
      if (!display.readAndDispatch) {
        display.sleep()
      }
    }
    display.dispose()
  }
}

极其简单的代码,但没有显示文字。
窗口中间应该有“hello swt”。
scala.version = 2.9.0-1,swt:3.7.0-win32
empty window

1 个答案:

答案 0 :(得分:5)

创建shell后添加此行:

shell.setLayout(new FillLayout)