Problem with rotating a Draw2D Label [message #243975] |
Tue, 01 July 2008 11:01 |
Eclipse User |
|
|
|
Originally posted by: benni5000.yahoo.de
Hi,
I am trying to rotate a Draw2D Label. I read that I have to override the
paintFigure() method of the Label class so that I call graphics.rotate()
before super.paintFigure(). My problem is that I get an
NullPointerException
at
org.eclipse.draw2d.SWTGraphics.checkSharedClipping(SWTGraphi cs.java:309)
when I call super.paintFigure(graphics).
Can anyone tell me, where I am wrong?
This is the code I used:
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
public class Window extends ApplicationWindow {
public Window() {
super(null);
}
public static void main(String[] args) {
Window window = new Window();
window.setBlockOnOpen(true);
window.open();
Display.getCurrent().dispose();
}
protected Control createContents(Composite parent) {
FigureCanvas canvas = new FigureCanvas(parent);
LightweightSystem lws = new LightweightSystem(canvas);
IFigure contents = new Figure();
contents.setLayoutManager(new XYLayout());
Label lbl = new VerticalLabel("Text");
lbl.setOpaque(true);
lbl.setBackgroundColor(ColorConstants.red);
contents.add(lbl, new Rectangle(10, 10, -1, -1));
lws.setContents(contents);
return canvas;
}
}
class VerticalLabel extends Label
{
public VerticalLabel() {}
public VerticalLabel(String str) {
super(str);
}
@Override
protected void paintFigure(Graphics graphics) {
graphics.rotate(90);
super.paintFigure(graphics);
}
}
Thanks,
Benhorn
|
|
|
Powered by
FUDForum. Page generated in 0.01752 seconds