<p>I have a form that tries to modify a JComponent's graphics context. I use, for example,</p>

<pre><code>((Graphics2D) target.getGraphics()).setStroke(new BasicStroke(5));
</code></pre>

<p>Now, immediately after I set the value and close the form, the change is not visible. Am I not allowed to modify a JComponent's graphics context? How else would I modify the stroke, color and transformations?</p>

<p>Thanks,</p>

<p>Vlad</p>

There are several problems with that approach. The first is that most components will set these things themselves when ever they are asked to repaint themselves. This means that your change will be lost every time the component gets to the point where it would actually use it. But, on an even more fundamental level than that, Graphics2D objects are not persistant. They are typically instantiated every time the component is redrawn, meaning that the Graphics2D object you got won't be the same the component will be using when redrawing.
What you need to do, to achieve this kind of thing is either to reimplement the specific component yourself, or implement a new look and feel that will affect the entire set of swing components. Have a look at the following link for further details about this:
http://today.java.net/pub/a/today/2006/09/12/how-to-write-custom-look-and-feel.html