Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: All
May 15, 1998

Margins in Dialog Boxes

When laying out a dialog box with a manager that does not provide space between the components and the edges of the box (such as a GridLayout manager), the following code will enable you to obtain a margin in a manner which is platform independent. The key is the use of the addNotify() and super.getInsets() methods to obtain the insets that the dialog would have if you did nothing to specify a margin. Then you can add your margins and generate a new insets object to be returned by your class's getInsets() method.
 
import java.awt.*;
public class YourClass extends Dialog {

	private Insets margins;
	public YourClass(Frame parent) {
		super(parent, "Dialog Title", true);
		addNotify();
		Insets border = super.getInsets();
		margins = new Insets(border.top    + 8, border.left  + 8,
		                     border.bottom + 8, border.right + 8);
	// Insert your code here
	}

	public Insets getInsets() {
	return margins;
	}
}
Tom Yarker
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date