Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I dynamically change font attributes, for instance, rendering a string in successively larger font sizes?

0
Posted

How can I dynamically change font attributes, for instance, rendering a string in successively larger font sizes?

0

Ans : Strictly speaking, you can’t. A Font object is created once and for all with fixed attributes, as specified in its constructor: public Font(String name, int style, int size) To get the effect of dynamically changing a font’s size or style, you need to create a new Font object with the desired values. For example, the following paint method draws up to twenty characters from a string in successively larger sizes: public void paint(Graphics g) { g.setColor(Color.blue); int maxLength = Math.min(20, inputString.length()); for (int i = 0; i < maxLength; ++i) { g.setFont(new Font("Courier", Font.ITALIC, 12 + i)); g.drawString(inputString.substring(i, i+1), 20 + 8*i + (int)(.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123