Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wie zentriere ich mein Fenster auf dem Bildschirm?

Empfohlene Antworten

Veröffentlicht

hi!

fang grad mit java an und hab mein erstes fenster mit buttons etc. programmiert.

nur ein problem.

ich will, dass es genau in der mitte vom bildschirm ist. egal bei welcher auflösung!

ich hab schon probiert ob es setLocation("Center") gibt, aber gibts natürlich nicht...lol.

könnt ihr mir vllt helfen? :S

wäre sehr freundlich von euch!

thx im vorraus!

Ich hab mir für sowas mal ne Hilfsklasse gemacht, in der es folgende Methode gibt:

public static void zentrierePosition(Window fenster) {

//	Monitorauflösung

	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

	int screenX = (int) screenSize.getWidth();

	int screenY = (int) screenSize.getHeight();


//	Fenstermaße

	int fensterX = fenster.getWidth();

	int fensterY = fenster.getHeight();


//	Mitte ermitteln

	int posX = screenX / 2 - fensterX / 2;

	int posY = screenY / 2 - fensterY / 2;


	fenster.setLocation(posX, posY);

}

Ich hab mir für sowas mal ne Hilfsklasse gemacht
Geht seit 1.4 noch viel einfacher:

frame.setLocationRelativeTo(null);

denn:

Sets the location of the window relative to the specified component. If [...] c is null, the window is centered on the screen.
frame.setLocationRelativeTo(null);
...Aso, den kannte ich auf jeden Fall noch nicht... Wieder was gelernt! Danke dafür!

Sonnige Grüße aus Hamburg!

Arvid.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.