java - JavaFX: Making an Object with a Shape and Text -
i trying make object can added pane. object contain shape , text.
through invoking:
pane#getchildren()#add(new textellipse(...))
it add ellipse text in center referenced pane.
my class such object represented below:
public class textellipse extends shapeellipse { public textellipse(final string text, final double x, final double y) { super(text, x, y); } @override protected shape createshape() { final double padding = 10; final ellipse ellipse = new ellipse(); ellipse.setradiusx(gettext().getlayoutbounds().getwidth() / 2 + padding); ellipse.setradiusy(10); ellipse.setstroke(color.black); ellipse.setfill(color.white); return ellipse; } } public abstract class textshape extends pane { private final text text; private final shape shape; public textshape(final string text, final double x, final double y) { this.text = new text(x, y, text); shape = createshape(); } protected abstract shape createshape(); public text gettext() { return text; } public shape getbackgroundshape() { return shape; } }
i've followed d.j. brown's method - however, when invoke
pane#getchildren()#add(new textellipse(...))
nothing shows on canvas.
however, when do:
pane#getchildren()#add(new textellipse(...)#getbackgroundshape())
the ellipse show up.
why won't ellipse , text show if add textellipse object?
this works
public class textellipse extends stackpane{ private final ellipse bubble; private final text text; textellipse(string text, double x, double y) { this.text = new text(x, y, text); system.out.println(this.text.getboundsinlocal().getwidth()); bubble = new ellipse (x, y, this.text.getboundsinlocal().getwidth() + 5, 15); bubble.setfill(color.yellow); getchildren().addall(bubble, this.text); } }
Comments
Post a Comment