You need draw2d.jar of GEF and swt.jar to run below program.
At first it's need to create FigureCanvas.
FigureCanvas connect Components and Figures.
Besides that there are LightweightSystem
FigureCanvas canvas = new FigureCanvas(shell);
Next ,it need to create Panel of Draw2D which is one of Figures. And set FlowLayout as Layout. On Draw2D figure is set as tree ,So it's need root Figure. And Method setContens() set root Figure .
Panel panel=new Panel(); panel.setLayoutManager(new FlowLayout(false)); canvas.setContents(panel);
Finally,it add labels of Draw2D. On Draw2D,there are no need to add a parent Figure argument,because it add a children figure to a parent Figure directly.
for(int i=0;i<3;i++){
Label label=new Label("draw2d "+i);
panel.add(label);
---
//all codes.
/*
* Created on 2005/07/28
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package example.draw2d;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Panel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
*
*
*/
public class Draw2DLabel {
public Draw2DLabel(Shell shell) {
shell.setBounds(0,0,150,150);
shell.setLayout(new FillLayout(SWT.VERTICAL));
FigureCanvas canvas = new FigureCanvas(shell);
Panel panel=new Panel();
panel.setLayoutManager(new FlowLayout(false));
canvas.setContents(panel);
for(int i=0;i<3;i++){
Label label=new Label("draw2d "+i);
panel.add(label);
}
}
public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display);
Draw2DLabel app=new Draw2DLabel(shell);
shell.open();
while(!shell.isDisposed()){
if (!display.readAndDispatch ()){
display.sleep ();
}
}
display.dispose();
}
}
}
1 comment:
Lottery Resultsplay online games
Post a Comment