2012-07-24 4 views
1

하나의 스크롤바를 RoundedRectangle에 추가하고 싶습니다. 나는 루트 그림에서 3 둥근 사각형을가집니다. 이제 각 둥근 사각형에 스크롤바를 추가하고 싶습니다. 둥근 사각형 또는 사각형 그림에 스크롤 막대를 추가 할 수 있습니까? 나는 다음과 같은 방법으로 사용했다. 그러나 그것은 나에게 어떠한 수치도 보여주지 않습니다. 어떻게 작동 시키는가? 아래의 예에서는 하나의 직사각형 만 추가했습니다.그림에 scrollpane

import org.eclipse.draw2d.ColorConstants; 
import org.eclipse.draw2d.Figure; 
import org.eclipse.draw2d.FigureCanvas; 
import org.eclipse.draw2d.LightweightSystem; 
import org.eclipse.draw2d.RoundedRectangle; 
import org.eclipse.draw2d.ScrollPane; 
import org.eclipse.draw2d.XYLayout; 
import org.eclipse.draw2d.geometry.Rectangle; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.FillLayout; 
import org.eclipse.swt.widgets.Canvas; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 

public class RoundedRectangleTest { 

    public static void main(String args[]) { 

     Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new FillLayout()); 
     shell.setText("Scrollpane Example"); 

     // Create a root figure and simple layout to contain all other figures 
     Figure root = new Figure(); 
     root.setFont(shell.getFont()); 
     root.setLayoutManager(new XYLayout()); 

     ScrollPane scrollPane = new ScrollPane(); 

     RoundedRectangle r = new RoundedRectangle(); 
     r.setBackgroundColor(ColorConstants.yellow); 
     Rectangle rect = new Rectangle(10, 10, 50, 50); 
     r.setBounds(rect); 

     scrollPane.setContents(r); 

     root.add(scrollPane); 

     FigureCanvas canvas = new FigureCanvas(shell, SWT.DOUBLE_BUFFERED); 
     canvas.setBackground(ColorConstants.white); 
     //canvas.setContents(scrollPane); 
     LightweightSystem lws = new LightweightSystem(canvas); 
     lws.setContents(root); 

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

    } 

} 

답변

1

나는 둥근 사각형을 얻을 관리하지 못했지만, 다음은 적어도 일반 사각형 작동 :

public class RoundedRectangleTest { 
    public static void main(String args[]) { 
     Display d = Display.getDefault(); 
     final Shell shell = new Shell(d); 

     LightweightSystem lws = new LightweightSystem(shell); 
     final Figure contents = new Figure(); 
     lws.setContents(contents); 
     contents.setLayoutManager(new GridLayout()); 

     IFigure rectangleFigure = createFigure(); 
     ScrollPane pane = new ScrollPane(); 

     /* delete following two lines if scrollbars not always visible */ 
     pane.setHorizontalScrollBarVisibility(ScrollPane.ALWAYS); 
     pane.setVerticalScrollBarVisibility(ScrollPane.ALWAYS); 
     pane.setContents(rectangleFigure); 
     contents.add(pane); 

     shell.open(); 
     shell.setText("Scrollpane Example"); 
     while (!shell.isDisposed()) { 
      if (!d.readAndDispatch()) 
       d.sleep(); 
     } 
    } 

    private static IFigure createFigure() { 
     RectangleFigure rectangleFigure = new RectangleFigure(); 
     rectangleFigure.setBackgroundColor(ColorConstants.yellow); 
     rectangleFigure.setSize(100, 100); 
     return rectangleFigure; 
    } 
} 

은 어쩌면 당신은 시작 지점으로 사용할 수 RectangleFigure 그러나와 같은 Figure를 만들 둥근 모서리.

+0

확인. 고마워요! – user414967