JButton myNewButton = new JButton("REPLACEMENT"); myButton = myNewButton;
Now, what do I need to do to get panel and the window to refresh and show the new myButton object that has the "REPLACEMENT" tag? Again, this is just a simplified example of what I'm trying to do... I've played around with repaint() and validate()/invalidate() methods for components, panels, windows - but none seem to work. How can I do this? How can I get the thing to repaint if I'm switching the component object underneath? Thanks!
I believe I tried that... It ends up removing the original button, but the new button never appears. I believe I was tesing this with JTable(s) though. I'll try doing it with buttons tomorrow at work. Thanks!
Originally posted by Alex Gorh: I believe I tried that... It ends up removing the original button, but the new button never appears. I believe I was tesing this with JTable(s) though. I'll try doing it with buttons tomorrow at work. Thanks!
I am not sure why it didn't work for you. It should work with any component. If you don't get it working, show us the code and we will help. Good luck.
It looks like you are just changing the text on the button. Would it be easier to just do a myButton.setText("Replace")? Then you don't have to go through any repaint, etc. It will be handled for you.
If you really have to add and remove the button. You could add the button with a specific index -
Then when you need to replace the button, do a myPanel.remove(1); (This might be the wrong method signature, but you get the idea.) You'll always be able to replace the button you need by just using the same index for adding and removing.
Regards, Aaron R>
subject: cannot get stuff to repaint - please help