• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Swing and AWT in an Applet

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an applet that displays some Swing controls in a Container using a BorderLayout. I have a JLabel in the NORTH area, a JSlider in the CENTER, and a JButton in the SOUTH. I need to draw two lines (using AWT I suppose), in the EAST and WEST areas, respectively. I don't mind using absolute co-ordinates to position them where I want, but when I try, the lines first get painted on a white background. Clicking this brings the slider in a grey box over the top of them. The JLabel and JButton aren't visible.
I'm positioning all the Swing components in the init() method, and drawing the lines in a separate paint(Graphics g) method. How do I get this to work?
This picture shows what I need (I've drawn the two lines in manually here).
Thanks for any help.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to use AWT here... just extend JComponent and put your drawing code in the paintComponent(Graphics) method instead of paint(Graphics). Once you start mixing AWT and Swing you are just asking for trouble.

Make sure the first line in the paintComponent() method is -


I can't tell from your description if you have separate components for drawing the lines or whether you are drawing them on the applet itself. I would strongly recommend doing this in a separate component, just to prevent any layout problems.
 
get schwifty. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic