1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public static Dimension getScreenSize(){
return java.awt.Toolkit.getDefaultToolkit().getScreenSize();
}
public static Insets getScreenInsets(){
return java.awt.Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());
}
public static void setRelativeLocation(Container cont,Point p,Dimension dim){
Insets insets = getScreenInsets();
Dimension tailleEcran = getScreenSize();
tailleEcran.width=tailleEcran.width-insets.right;
tailleEcran.height=tailleEcran.height-insets.bottom;
if (p.x+p.y==0){ // centrer à l'ecran le popup
p.x=(tailleEcran.width-dim.width)/2;
p.y=(tailleEcran.height-dim.height)/2;
}
if (p.x+dim.width>tailleEcran.width){ // perte sur la largeur
p.x=(tailleEcran.width-dim.width); // recalcule x pour coller à droite
}
if (p.y+dim.height>tailleEcran.height){ // perte en hauteur
p.y=(tailleEcran.height-dim.height); // recalcule y pour coller en bas
}
cont.setLocation(p.x,p.y);
insets=null;
tailleEcran=null;
} |
Partager