Swing: Définir la position d’affichage d’une fenêtre

Author:

 set, swing, awt, JFrame
Download

import java.awt.*;
 
 
 
 
public class WindowsCenter {
 
    /** Définir la position d'affichage d'une fenêtre de type Frame, JFrame, Dialog, etc. */
 
    public static void centre(Window w) {
 
        Dimension windowsSize = w.getSize( ), 
        screenSize = Toolkit.getDefaultToolkit( ).getScreenSize( );
 
        int x = (screenSize.width - windowsSize.width) / 2;
 
        int y = (screenSize.height- windowsSize.height)/ 2;
 
        w.setLocation(x, y);
 
    }
    public static void center(Window w) {
 
        WindowsCenter.centre(w);
 
    }
 
}