Manually Positioning Components
It is possible to precisely position widgets on the screen using x and y pixel coordinates that are relative to the applet's panel. Before you get the details you should hear why this is a bad idea:
- Not every instance of your applet will have the same size panel to work with. You should only do this when the applet will only run on your web pages so you can control the applet's size. Free-standing windows may even be resized by the user on the fly. If you've used a layout
manager to position your components, they'll be adjusted immediately to fit the new window size. This behavior is extremely hard to duplicate if you don't use a layout manager.
- Components use varying amounts of space on different platforms. You should probably only use these techniques when you are writing a single-platform, compiled Java application. You should not use them for applets.
- Laying out components manually is a lot of work, especially given the lack of Visual Basic like interface drawing environments. Don't you have better things to do with your time than moving widgets one pixel to the left, recompiling and running the applet only to discover the widget was probably better off where it started out?
- The
GridBagLayout
and/or nested panels can probably do everything you want to do with manual layout anyway.
Previous | Next | Top
Last Modified November 11, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu