2012-03-27 2 views
0

SWT 애플리케이션이 있습니다. 응용 프로그램을 시작하고 창을 볼 수있는 상태에서 일부 작업 (진행률 표시 줄 포함)을 실행해야합니다. 어떻게/어떻게해야합니까?응용 프로그램 창이 생성되어 표시되면 작업을 실행하는 방법은 무엇입니까?

import org.eclipse.jface.action.MenuManager; 
import org.eclipse.jface.action.StatusLineManager; 
import org.eclipse.jface.action.ToolBarManager; 
import org.eclipse.jface.window.ApplicationWindow; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.graphics.Point; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Control; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 

public class TestApp extends ApplicationWindow { 

    /** 
    * Create the application window. 
    */ 
    public TestApp() { 
     super(null); 
     createActions(); 
     addToolBar(SWT.FLAT | SWT.WRAP); 
     addMenuBar(); 
     addStatusLine(); 
    } 

    /** 
    * Create contents of the application window. 
    * @param parent 
    */ 
    @Override 
    protected Control createContents(Composite parent) { 
     Composite container = new Composite(parent, SWT.NONE); 

     return container; 
    } 

    /** 
    * Create the actions. 
    */ 
    private void createActions() { 
     // Create the actions 
    } 

    /** 
    * Create the menu manager. 
    * @return the menu manager 
    */ 
    @Override 
    protected MenuManager createMenuManager() { 
     MenuManager menuManager = new MenuManager("menu"); 
     return menuManager; 
    } 

    /** 
    * Create the toolbar manager. 
    * @return the toolbar manager 
    */ 
    @Override 
    protected ToolBarManager createToolBarManager(int style) { 
     ToolBarManager toolBarManager = new ToolBarManager(style); 
     return toolBarManager; 
    } 

    /** 
    * Create the status line manager. 
    * @return the status line manager 
    */ 
    @Override 
    protected StatusLineManager createStatusLineManager() { 
     StatusLineManager statusLineManager = new StatusLineManager(); 
     return statusLineManager; 
    } 

    /** 
    * Launch the application. 
    * @param args 
    */ 
    public static void main(String args[]) { 
     try { 
      TestApp window = new TestApp(); 
      window.setBlockOnOpen(true); 
      window.open(); 
      Display.getCurrent().dispose(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    /** 
    * Configure the shell. 
    * @param newShell 
    */ 
    @Override 
    protected void configureShell(Shell newShell) { 
     super.configureShell(newShell); 
     newShell.setText("New Application"); 
    } 

    /** 
    * Return the initial size of the window. 
    */ 
    @Override 
    protected Point getInitialSize() { 
     return new Point(450, 300); 
    } 

} 

답변

1

페인트 수신기를 사용할 수 있습니다.

@Override 
protected Control createContents(Composite parent) { 
    Composite container = new Composite(parent, SWT.NONE); 

    container.addPaintListener(new PaintListener() { 

     @Override 
     public void paintControl(PaintEvent e) { 
      System.out.println("I'm ready to go..."); 

     } 
    }); 
    return container; 
} 
+0

'paintControl' 메서드가 잘못 호출되었습니다. 죄송하지만,'getShell(). addPaintListener()';)와 함께 작동합니다. – marioosh

+0

그러나 부분적으로 작동하는 방법 (다시 한 번 그 방법을 호출하는 방법)이지만 청취자를 등록 해 주신 것에 대해 감사드립니다. – marioosh

0

청취자를 등록하는 아이디어에 감사드립니다. 나는 저를 위해 작동하는 무언가를 찾아 냈습니다 - ShellListener. 아래 예.

+0

하지만 shellActivated는 창에 포커스가있을 때마다 실행되므로이 ​​솔루션으로 문제가 해결되지 않는다고 생각합니다. 프로그램 창을 변경하거나 모달 대화 상자에서 돌아온 후 대신 SWT.Show를 사용합니다. – altralaser

관련 문제