/* * MyCentralizedJDialog.java * * Created on November 18, 2004, 2:55 PM */ package cz.muni.fi.bronchus.gui; import javax.swing.*; import java.awt.*; /** * * @author xudrzal */ public class MyCentralizedJDialog extends javax.swing.JDialog { /** Creates a new instance of MyCentralizedJDialog */ public MyCentralizedJDialog(java.awt.Frame parent, boolean modal) { super(parent,modal); } public MyCentralizedJDialog(javax.swing.JDialog parent, boolean modal) { super(parent,modal); } public void centerInParent() { int x; int y; Container parent = this.getParent(); Point topLeft = parent.getLocationOnScreen(); Dimension parentSize = parent.getSize(); Dimension ownSize = this.getSize(); if (parentSize.width > ownSize.width) {x = ((parentSize.width - ownSize.width)/2) + topLeft.x;} else {x = topLeft.x;} if (parentSize.height > ownSize.height) {y = ((parentSize.height - ownSize.height)/2) + topLeft.y;} else {y = topLeft.y;} this.setLocation(x, y); this.requestFocus(); } public void centerInScreen() { Dimension dim = this.getToolkit().getScreenSize(); Rectangle bounds = this.getBounds(); this.setLocation((dim.width - bounds.width) / 2, (dim.height - bounds.height) / 2); this.requestFocus(); } }