Java Code Examples for javax.swing.JFrame.getBounds()

The following are Jave code examples for showing how to use getBounds() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: About.java   View Source Code Vote up 5 votes
/** Creates new form About */
public About(JFrame parent) {
    super(parent,true);
    initComponents();
    pack();
    Rectangle parentBounds = parent.getBounds();
    Dimension size = getSize();
    // Center in the parent
    int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
    int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
    setLocation(new Point(x, y));
}
 
Example 2
Project: slick   File: Test_SlickLayout.java   View Source Code Vote up 5 votes
/**
 * 
 * Tests
 * 
 */

private static boolean borderTest()
{	
	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
	
	JPanel contentPanel = new JPanel();
	contentPanel.setLayout( new SlickLayout() );
	contentPanel.setBorder( BorderFactory.createEmptyBorder(10, 10, 10, 10) );
	
	JPanel comp1 = new RandomColorPanel( new Dimension( 200, 200 ), "1" );
	contentPanel.add(comp1, new SlickConstraint(0, SlickConstraint.HorizontalPack, SlickConstraint.VerticalPack) );
	
	frame.add(contentPanel);
	frame.pack();
	//frame.setVisible(true);
	frame.dispose();
	
	boolean pass = true;
	
	//java.awt.Rectangle[x=62,y=0,width=236,height=259]
	Rectangle frameBounds = frame.getBounds();
	pass &= (frameBounds.width == 236)&(frameBounds.height == 259);
	
	//java.awt.Rectangle[x=0,y=0,width=220,height=220]
	Rectangle contentPanelBounds = contentPanel.getBounds();
	pass &= (contentPanelBounds.width == 220)&(contentPanelBounds.height == 220);
	pass &= (contentPanelBounds.x == 0)&(contentPanelBounds.y == 0);
		
	//java.awt.Rectangle[x=10,y=10,width=200,height=200]
	Rectangle comp1Bounds = comp1.getBounds();
	pass &= (comp1Bounds.width == 200)&(comp1Bounds.height == 200);
	pass &= (comp1Bounds.x == 10)&(comp1Bounds.y == 10);
	
	return pass;
}
 
Example 3
Project: Java-Swing-Helper   File: SwingWindow.java   View Source Code Vote up 5 votes
/**
 * Initialize the contents of the frame.
 */
private void initialize(String title, Rectangle bounds) {
	frame = new JFrame();
	frame.setBounds(bounds);
	frame.setMinimumSize(frame.getBounds().getSize());
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);
	frame.setTitle(title);
	this.title = title;
	this.originalBounds = frame.getBounds();
}