Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top