Reputation: 159
I have a functioning Java applet which can be embedded into a web page and wish to now add some swing components for additional functions. However whenever I add a component like a JLabel, it simply does not appear on the viewport/canvas unless I remove my entire paint method. The latter option allows me to add swing components but naturally I then cannot render any shapes. It appears to resemble an eXclusive OR (XOR), either one but not the other.
Is there anyway in a native Java applet to add swing components and still maintain the paint(Graphics g) method. Please note that I am inheriting from Applet and not JApplet.
Upvotes: 1
Views: 893
Reputation: 159
I was able to visualise the components over the applet canvas by invoking
paintComponents(g);
Thus the components are thereafter painted AFTER the actual paint(Graphics g) method completes its epoch.
Upvotes: 0
Reputation: 562
If you override paint method in applet then there is no simple way.
What you could do instead of overriding paint in applet.
Upvotes: 3
Reputation: 32391
I suggest that you add the components to a separate panel that doesn't override paint
. By overridding paint
, you are customizing the way the component is drawn, so the layout manager and the components it has to manage do not count, it's only the implementation of paint
you wrote that dictates how stuff is rendered.
So, your applet would contain a panel with the components and a panel that does the custom painting.
Upvotes: 2