문제

Is there a way to align text from g.drawString() to the bottom center of a java applet?

I am also hoping for a way that is fluid between full-screen and small screen.

도움이 되었습니까?

해결책

Yes, start by taking a look at Measuring Text

String text = "Happy at the bottom";
FontMetrics fm = g.getFontMetrics();
int x = (getWidth() - fm.stringWidth(text)) / 2;
int y = (getHeight() - fm.getHeight()) + fm.getAscent();
g.drawString(text, x, y);

The next question that needs to asked, is could what you want be achieved by using a JLabel and a BorderLayout (or other compound layout)....?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top