You can give an alignment suggestion to the layout manager by using:
label.setAlignmentY(JLabel.CENTER_ALIGNMENT);
If this doesn't help then post a proper SSCCE that demonstrates the problem.
Frage
numBox
is a square JLabel
like the ones in the game 2048. The text where the number goes will not vertically center.
neither
numBox.setVerticalAlignment(JLabel.CENTER);
nor
numBox.setVerticalTextPosition(JLabel.CENTER);
are working.
Text shows up horizontally centered but at the top of the box that the label shows up in. How do I get the text to show up in the middle of the JLabel?
Lösung
You can give an alignment suggestion to the layout manager by using:
label.setAlignmentY(JLabel.CENTER_ALIGNMENT);
If this doesn't help then post a proper SSCCE that demonstrates the problem.