How can I place an outline around a group of components to show explicitly how the components are grouped?
Ans : You can write your own Panel subclass that draws an outline and specifies appropriate inset values to ensure that the panel’s components stay inside the outline. Panel, as a subclass of Component, includes a paint method that draws the panel on the screen. Panels typically just draw a background color on which their components are placed, but you can define your own paint method to draw whatever you like in the panel. The drawRect method in the Graphics class provides a very simple means to draw an outline. The following paint method, for example, uses drawRect to provide a blue outline: /* using JDK 1.1: */ public void paint(Graphics g) { Dimension size = getSize(); g.setColor(Color.blue); g.drawRect(2, 2, size.width – 5, size.height – 5); } Anything you draw on a panel using paint, however, can be covered by components contained in the panel. Therefore, you need to inform the panel’s layout manager that space at the margins should be left free for the outline. To do this, overr