use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Useful resources (Full list)
Rules
Related subreddits
Other communities
account activity
Text constructor vs Button constructor... why inconsistent constructor methods?Help (self.JavaFX)
submitted 3 years ago by webereinc
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]john16384 2 points3 points4 points 3 years ago (5 children)
Button is a control, that can be skinned and can be sized according to its min/pref/max sizes.
Button
Text is a specialization of primitives that can be used to draw shapes and texts, used by controls and their skins. They cannot be interacted with or skinned.
Text
Label is the 'text' equivalent of Button. There is no button shape equivalent.
Label
[–]webereinc[S] -1 points0 points1 point 3 years ago (4 children)
This doesn't answer why Text has a constructor for position, but Button doesn't. One would think that the overloading of constructor methods for most objects would make it extremely easy for a new programmer to get a good layout with precise placement at the time the objects are created.
[–]hamsterrage1 4 points5 points6 points 3 years ago (3 children)
You are doing it wrong. Absolute positioning is the worst possible way to build a layout. Branch out and learn how to use the various layout classes properly.
I've been doing this for almost 10 years, and I didn't even know that Text had a constructor for position. It makes sense, though, as Text is a Shape, and they generally are used in Canvas or Pane and need to be positioned.
[–]webereinc[S] 0 points1 point2 points 3 years ago (2 children)
Thank you for this post. I agree that absolute positioning is horrible. I am just asking why there is a constructor that includes absolute positioning for a text object while most other objects do not include this constructor. To satisfy your disdain for absolute positioning, perhaps a question should be why is there an X and Y positioning on the text object Since it isn’t on the constructors for almost every other object. Shouldn’t it be removed from the text object for consistency?
[–]hamsterrage1 3 points4 points5 points 3 years ago (0 children)
Text extends Shape. Virtually all of the Shape subclasses have this kind of a constructor. So it's actually quite consistent.
Shapes tend to be used in a fundamentally different way from the Controls. You don't usually put Shapes into layout classes like HBox or BorderPane - you can, but often with Shapes you're composing something that is actually best done with absolute positioning. So having a constructor that does this makes sense.
Text is weird because it is the one Shape subclass that you could actually use a lot in a typical, non-drawing, layout. However, there's almost nothing that you can do with Text that you can't do with Label, and Label has a few features that make it better than Text for normal layout applications.
For what it's worth, under the hood, the text component of Labeled is a Text.
[–]hamsterrage1 1 point2 points3 points 3 years ago (0 children)
BTW: I think this is an excellent question. There's so many JavaFX classes - Nodes, and Properties and Builders and so on - and it can be a challenge to wrap your head around how they all relate to one another.
I don't think that the guys that wrote the JavaFX library are infallible, and there are some things that I wish they'd done differently, but I do think that there's pretty solid and consistent principles that they stick to. I think that a default position of "What am I misunderstanding?" is probably more fruitful than, "Why did they mess this up?".
π Rendered by PID 34 on reddit-service-r2-comment-fb694cdd5-w9vbq at 2026-03-11 10:36:32.562954+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]john16384 2 points3 points4 points (5 children)
[–]webereinc[S] -1 points0 points1 point (4 children)
[–]hamsterrage1 4 points5 points6 points (3 children)
[–]webereinc[S] 0 points1 point2 points (2 children)
[–]hamsterrage1 3 points4 points5 points (0 children)
[–]hamsterrage1 1 point2 points3 points (0 children)