Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

jframe mittig positionieren

public class MyFrame {

   public MyFrame(String title) {
      JFrame frame = new JFrame(title);
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      int windowWidth = 800; //Breite des Programmfensters in Pixel
      int windowHeight = 600; //Höhe des Programmfensters in Pixel
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //Bildschirmdimensionen in Pixeln holen
      frame.setBounds((screenSize.width-windowWidth)/2, (screenSize.height-windowHeight)/2, windowWidth, windowHeight);
      frame.setVisible(true);
   }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              new MyFrame("Byte-Welt.net");
          }
      });
   }
}
Source by wiki.byte-welt.net #
 
PREVIOUS NEXT
Tagged: #jframe #mittig #positionieren
ADD COMMENT
Topic
Name
6+8 =