> Hiya, I think this is a fairly common JPanel related question
What did your searches of the group/s reveal
(note that the rel GUI experts hang out at c.l.j.gui.
>.... and would love any help, ..
Help searching? What are your current search terms?
Andrew T.
> Hiya, I think this is a fairly common JPanel related question and would
> love any help,
[quoted text clipped - 3 lines]
> I also want to be able to change the width/height/x/y of the rectangle
> then have it redrawn. (Im stuck at this point)
You need to have some way of getting the parameters. Probably the
simplest is to use JTextFields to input the data.
> Do I have to call some kind of redraw command on the JPanel to have it
> updated? Or do I do it on the rectangle itself? Or some other way
> perhas?
You draw your rectangle in the paintComponent() method. You need to
change the parameters and call repaint() on your JPanel or its parent to
cause your JPanel to be redrawn with the new data.
> Pretty stuck, any sample code would be great
Show us the code you wrote to draw your rectangle and we can help you
from that start.

Signature
Knute Johnson
email s/nospam/knute/
Ben Kraufmann - 25 Aug 2006 11:13 GMT
>> Do I have to call some kind of redraw command on the JPanel to have it
>> updated? Or do I do it on the rectangle itself? Or some other way
[quoted text clipped - 3 lines]
> change the parameters and call repaint() on your JPanel or its parent to
> cause your JPanel to be redrawn with the new data.
Be careful when using repaint(). You have to make sure that only the
Swing thread calls it, otherwise you can run into serious trouble.
So, call repaint() within an ActionListener (button pressed or
something) or use the SwingUtility-Methods invokeLater() or invokeAndWait().
Ben
Babu Kalakrishnan - 25 Aug 2006 12:03 GMT
> >> Do I have to call some kind of redraw command on the JPanel to have it
> >> updated? Or do I do it on the rectangle itself? Or some other way
[quoted text clipped - 8 lines]
> So, call repaint() within an ActionListener (button pressed or
> something) or use the SwingUtility-Methods invokeLater() or invokeAndWait().
That's incorrect. A call to repaint() only queues up a request for the
component to be repainted, and swing will make sure that it performs
the actual painting task in the EDT. repaint() is one of the few
methods in Swing that have been documented to be safe to call from a
thread other than the EDT.
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html#exceptions
(Note that the first "exception" mentioned on that page has later been
marked as not being 100% safe) - See the section "Event-Dispatching
Thread" in the article
http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
BK