0
캔버스의 크기 제한에 의해 허용되는 것보다 캔버스에서 더 많이 표시하려고합니다. 나는 이것에 몇 가지 방법이 있다는 것을 알고있다. FigureCanvas를 사용할 수는 있지만 뷰포트가 어떻게 연관되어 있는지 확신 할 수 없습니다. 나는 ScrolledComposite를 만들고 그 안에 캔버스를 배치하기로 결정했다. 내 문제는 스크롤 막대가 나타나지만 캔버스에 표시되는 것과 아무런 차이가 없다는 것입니다. 누구든지 이것을 고치기의 올바른 방향으로 가르쳐 주시겠습니까? 감사. * 문제를 보여주는 짧은 테스트 가능한 코드를 추가했습니다.캔버스에 대한 스크롤링 사용 설정 SWT Draw2d
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.SimpleRaisedBorder;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.xml.sax.SAXException;
import org.eclipse.swt.custom.ScrolledComposite;
public class ScrollDemo extends Dialog {
protected Shell shell;
protected IFigure panel;
protected IFigure v_panel;
public static void main(String[] args)
{
ScrollDemo act= new ScrollDemo(new Shell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
act.open();
}
/**
* Create the dialog.
* @param parent
* @param style
*/
public ScrollDemo(Shell parent, int style) {
super(parent, style);
setText("Scrolling Demo");
}
/**
* Open the dialog.
* @throws SAXException
*/
public void open(){
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the dialog.
*/
private void createContents(){
shell = new Shell(getParent(), getStyle());
shell.setSize(475, 375);
shell.setText(getText());
shell.setLayout(new GridLayout(1, false));
ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_MAGENTA));
GridData gd_scrolledComposite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_scrolledComposite.widthHint = 453;
gd_scrolledComposite.heightHint = 245;
scrolledComposite.setLayoutData(gd_scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
Canvas canvas = new Canvas(scrolledComposite, SWT.H_SCROLL | SWT.V_SCROLL);
canvas.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_YELLOW));
scrolledComposite.setContent(canvas);
scrolledComposite.setMinSize(canvas.computeSize(SWT.DEFAULT, SWT.DEFAULT));
LightweightSystem lws = new LightweightSystem(canvas);
panel = new Figure();
lws.setContents(panel);
int starting_xpos= 0;
int starting_ypos= 0;
makeStructure(starting_xpos, starting_ypos, 0);
}
private void makeStructure(int starting_xpos, int starting_ypos, int index)
{
org.eclipse.draw2d.Label lblRoot= new org.eclipse.draw2d.Label();
Rectangle rect= new Rectangle(starting_xpos, starting_ypos, 200, 25);
//Anything longer than 200 cannot be displayed
lblRoot.setText("BAAAAAAAAAAAB");
lblRoot.setBorder(new SimpleRaisedBorder());
lblRoot.setForegroundColor(ColorConstants.black);
lblRoot.setVisible(true);
lblRoot.setOpaque(true);
lblRoot.setBounds(rect);
panel.add(lblRoot);
if (index<10)
{
makeStructure(starting_xpos+20, starting_ypos+50, index+1);
}
}
}
대단히 감사합니다. 스크롤을 통해 액세스 할 수있는 캔버스의 크기를 늘리려면 어떻게해야합니까? 캔버스/뷰포트의 경계를 변경하면 나에게 아무런 영향을주지 않습니다. – Asher
@Asher 새로운 수치를 추가했기 때문에 수치를 올릴 필요가 있습니까? 범위를 벗어났습니다. 단순히 수치를 올리고 싶습니까? – Baz
두 경우 모두 실제로 필요합니다 ... – Asher