trouve ci-joint le source d'une JFrame possédant une nouvelle fonction centerTheWindow(), libre à toi de le modifier à ta convenance:
public myFrame extends JFrame {
//center the frame on the screen public void centerTheWindow(){ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
this.setVisible(true); } }
------------------------------- Réponse au message : -------------------------------
Je voudrais savoir comment centrer une Window. Merci de mettre le code source
|