Yo - im making an animation which draws a string to a panel and moves it once the class is loaded. This all works fine but I want to change the colour of the string to white, the background will be black by the way, as well as make it bold and italic.

I've tried using HTML tags, which work on the other strings i have created. I also tried using a JLabel, which works but I can't draw a component using:

Graphics2D g2d = (Graphics2D) g;
		g2d.drawString( text, textX, textY );

g2d doesn't contain a draw component option. So what are my options?

Also how do I specify a components position, I used the setBounds() method as well as the setLocation() method, neither worked. Does it matter that it was within a JPanel?


7 Years
Discussion Span
Last Post by Ezzaral

You can use those methods to set your component locations if you set your layout to null. If you move the component, you won't need to use the graphics methods.

If you want to use the graphics methods instead, you could make a small banner component that paints the moving text across the black background and use setFont() and setColor() to stylize the text.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.