下面列出了javax.swing.JDialog#getHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 屏幕中间显示对话窗口
*
* @param i_JDialog
*/
public void showCreate(JDialog i_JDialog)
{
Toolkit v_Toolkit = Toolkit.getDefaultToolkit();
int v_X = (v_Toolkit.getScreenSize().height - i_JDialog.getHeight()) / 2;
int v_Y = (v_Toolkit.getScreenSize().width - i_JDialog.getWidth() ) / 2;
i_JDialog.setLocation(v_Y ,v_X);
i_JDialog.setVisible(true);
}
/**
* Floats the associated toolbar at the specified screen location,
* optionally centering the floating frame on this point.
*/
public void floatToolBar(int x, int y, final boolean center) {
final JDialog floatFrame = getFloatingFrame();
if (floatFrame == null)
return;
final Container target = ourDockLayout.getTargetContainer();
if (target != null)
target.remove(ourToolBar);
floatFrame.setVisible(false);
floatFrame.getContentPane().remove(ourToolBar);
ourToolBar.setOrientation(ToolBarLayout.HORIZONTAL);
floatFrame.getContentPane().add(ourToolBar, BorderLayout.CENTER);
floatFrame.pack();
if (center) {
x -= floatFrame.getWidth() / 2;
y -= floatFrame.getHeight() / 2;
}
// x and y are given relative to screen
floatFrame.setLocation(x, y);
floatFrame.setTitle(ourToolBar.getName());
floatFrame.setVisible(true);
ourToolBarShouldFloat = true;
if (target != null) {
target.validate();
target.repaint();
}
}
/**
* Sets the dialog position in the centre of the application window.
*
* @param dialog the dialog to centre
*/
public void centreDialog(JDialog dialog) {
if ((frame != null) && (dialog != null)) {
final int x = frame.getX() + (frame.getWidth() - dialog.getWidth()) / 2;
final int y = frame.getY() + (frame.getHeight() - dialog.getHeight()) / 2;
dialog.setLocation(x, y);
}
}
@Override
public void ancestorAdded(AncestorEvent event) {
JDialog parent = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, panel);
if (parent != null) {
height = parent.getHeight() ;
}
}
private void center(JDialog dialog) {
int x = owner.getLocation().x + (owner.getWidth() - dialog.getWidth()) / 2;
int y = owner.getLocation().y + (owner.getHeight() - dialog.getHeight()) / 2;
dialog.setLocation(x, y);
}