[API Review] RT-16206: Both Button and ButtonBase controls should have another constructor.
Richard Bair
richard.bair at oracle.com
Fri Jan 18 15:42:37 PST 2013
http://javafx-jira.kenai.com/browse/RT-16206
I've uploaded the patch. Basically it just contains a new constructor added to Labeled, ButtonBase, and Button:
/**
* Creates a Labeled with a graphic. This is the same as
* creating a basic Label and calling {@link #setGraphic(javafx.scene.Node)}.
* @param graphic The graphic for the label
*/
public Labeled(Node graphic) {
setGraphic(graphic);
}
/**
* Creates a ButtonBase with a graphic. This is the same as
* creating a ButtonBase using the default constructor and calling
* {@link #setGraphic(javafx.scene.Node)}.
*
* @param graphic The graphic for the label
*/
public ButtonBase(Node graphic) {
super(graphic);
}
/**
* Creates a Button with a graphic. This is the same as
* creating a Button using the default constructor and calling
* {@link #setGraphic(javafx.scene.Node)}.
*
* @param graphic The graphic for the label
*/
public Button(Node graphic) {
super(graphic);
}
There are two interesting things here. First, there are a lot of subclasses of Labeled, so why only Button? I think the answer is, because having a button with no text is somewhat common (think, toolbar buttons) whereas checkboxes without text is uncommon, radio buttons without text is uncommon, labels without text is uncommon, etc. And of course we can always add a constructor in the future if somebody cares enough to file a JIRA :-).
The second question is more interesting to me. If you set the graphic via this constructor, should the contentDisplay also be defaulted to GRAPHIC_ONLY? I decided no. The reason is that if you use the text-based constructor, it doesn't set it to TEXT_ONLY. The other reason is that it would perhaps be surprising that:
Button b = new Button(graphic);
b.setText("Yo");
ends up showing only the graphic and not the text. I felt it better to avoid the side-effect.
Richard
More information about the openjfx-dev
mailing list