本文整理汇总了Java中javax.swing.JFrame.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java JFrame.getBounds方法的具体用法?Java JFrame.getBounds怎么用?Java JFrame.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.getBounds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: About
import javax.swing.JFrame; //导入方法依赖的package包/类
/** 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));
}
示例2: borderTest
import javax.swing.JFrame; //导入方法依赖的package包/类
/**
*
* 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;
}
示例3: initialize
import javax.swing.JFrame; //导入方法依赖的package包/类
/**
* 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();
}