0

In draw2d,How can I draw a figure without having any border? How to implements the CustomBorder for rectangles to remove the border? I know if we implement a class which extends Border, and in the paint method what should I do to remove the border?

user414967
  • 5,225
  • 10
  • 40
  • 61

2 Answers2

2

Figures don't have a border unless you explicitly set one by calling setBorder(..). If you just want a blank figure that doesn't draw anything, then new Figure() will give you just that. There's no need to implement any custom borders or figures. If you are using a Rectangle then that's exactly what you will get: a rectangle; which is what you probably confused for a border.

Frettman
  • 2,251
  • 1
  • 13
  • 9
  • Yaa true. But If a draw a figure and try to show it in the the canvas it is giving me a blank figure. that means it is not visible. I tried to set the background to see whether can make it visible or not.But I could not see. So I assumed that Figures are basically a kind of container to contain other shapes. Is that correct? Please make me understand. That is the reason I approached with the custom rectangle without having any border. – user414967 May 21 '12 at 09:30
  • With "figure.setOpaque(true)" the `Figure` will draw its background color. – Frettman May 21 '12 at 10:01
1

You can disable the border with figure.setBorder(null); or you can put it in the constructor:

public static  class BorderlessFigure extends Figure {
    public BorderlessFigure() {
        ToolbarLayout layout = new ToolbarLayout();
        setLayoutManager(layout);   
        setBorder(null);
        add(new Label("test"));  
    }
}

If you want a Border that does not paint anything you can extend org.eclipse.draw2d.AbstractBorder:

public class NoBorderBorder extends AbstractBorder {
    @Override
    public void paint(IFigure f, Graphics g, Insets i) { }

    @Override
    public Insets getInsets(IFigure f) {
        return new Insets(0);
    }
}

I don't know why would you do that though.

Peter Bagyinszki
  • 1,069
  • 1
  • 10
  • 29
  • Hi,Thanks for the suggestion. I tried in that way before I posted here. But did not work at all. Then I tried to use custom figure which extends Rectangle figure. Then I could draw rectangle without having any border. – user414967 May 21 '12 at 06:28