2012-12-11 5 views
-4

이미지를 툴 아이템으로 설정하고 싶습니다. 그러나, 내 프로그램이 작동하지 않으며, 그냥 빈 창이 표시됩니다. 지금까지ToolItem에 이미지 추가

내 코드 :

import org.eclipse.swt.*; 

import org.eclipse.swt.graphics.Image; 
import org.eclipse.swt.widgets.*; 

public class test 
{ 
    public static void main(String [] args) 
    { 
     Display display = new Display(); 
     final Shell shell = new Shell(display); 
     shell.setSize(900, 200); 

     final ToolBar t=new ToolBar(shell,SWT.NONE); 
     Image image=new Image(display,"C:\\Users\\ART\\Documents\\Parsian\\bottum.jpg"); 

     final ToolItem ti=new ToolItem(t,SWT.NONE); 
     ti.setImage(image); 
     ti.setText("test"); 

     shell.open(); 
     while (!shell.isDisposed()) 
     { 
      if (!display.readAndDispatch()) 
       display.sleep(); 
     } 
     display.dispose(); 
    } 
} 

답변

1

어떤 코드가없는 것은 마법 기능 Control#pack()은이 :

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

    final ToolBar bar = new ToolBar(shell, SWT.FLAT | SWT.WRAP | SWT.RIGHT); 
    final ToolItem item = new ToolItem(bar, SWT.PUSH); 
    Image image = new Image(display, "img/star.png"); 
    item.setImage(image); 
    item.setText("test"); 

    /* Add this pack() call */ 
    bar.pack(); 
    shell.setSize(400, 250); 
    shell.open(); 
    while (!shell.isDisposed()) 
    { 
     if (!display.readAndDispatch()) 
      display.sleep(); 
    } 
    display.dispose(); 
} 

은 다음과 같습니다

enter image description here