我现在在做一个实验应用,需要一个GUI提供操作,打算用swt(刚开始学)。swt调用的是一个独立的程序包,这个程序包主要就是数据库操作。我希望能在swt窗口中动态的显示sql信息,在程序包中的输出是普通的Console输出,怎么能在swt中显示这些输出并且不会有swt组件嵌入到那个独立的程序包。说白了,就是象eclipse一样,能在GUI内显示Console信息。明白的帮忙指点一下啊。。

解决方案 »

  1.   

    能够在Text中捕捉System.out.print吗,主要是输出的内容未定,该如何捕捉。我现在打算用log4j,配置成输出到console和文件,现在怎么能使其日志内容也输出swt中呢?eclipse等怎么做到呢?
      

  2.   

    可以用TextArea,详细的可查API文档
      

  3.   

    没在swt中看到TextArea,是在jface中,我现在还没有什么好的文档,明白的不吝赐教啊
      

  4.   

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.widgets.*;/**
     * This class demonstrates text fields
     */
    public class TextExample {
      public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));
        // Create a single-line text field
        new Text(shell, SWT.BORDER);    // Create a right-aligned single-line text field
        new Text(shell, SWT.RIGHT | SWT.BORDER);    // Create a password text field
        new Text(shell, SWT.PASSWORD | SWT.BORDER);    // Create a read-only text field
        new Text(shell, SWT.READ_ONLY | SWT.BORDER).setText("Read Only");    // Create a multiple-line text field
        Text t = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        t.setLayoutData(new GridData(GridData.FILL_BOTH));    shell.open();
        while (!shell.isDisposed()) {
          if (!display.readAndDispatch()) {
            display.sleep();
          }
        }
        display.dispose();
      }
    }
      

  5.   

    i think Label is better.