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.

Empfohlene Antworten

Veröffentlicht

Hi...

Hab ein problem beim positionieren eines JLabels.

		super("Main"); 


		setLayout(new BorderLayout());

		setDefaultCloseOperation(EXIT_ON_CLOSE);        


		status = new JLabel("ready to play...");

		Headline = new JLabel();

		Headline.setIcon(new ImageIcon("D:/imgs/headline.jpg"));       

		game = new CardGame(this);                

		game.init((rows * col) / 2, 80, 80);         

		CardPanel cp = new CardPanel(rows,col);        

		cp.populate(game.getCards()); 


		add(BorderLayout.NORTH, Headline);

		add(BorderLayout.CENTER, cp);        

		add(BorderLayout.SOUTH, status);

		pack();       

		setVisible(true);    

		setResizable(false);

also das Fenster könnte bei jedem Start eine andere größe haben und das JLabel Headline müsste immer oben mittig sein.

also das es oben steht hab ich ja schon geschafft :bimei

Gruß...

Und warum willst du unbedingt dass das JLabel mittig ist?

Wenn du den BorderLayoutManager benutzt, dann wird das JLabel über die gesamte Breite deines Fensters ausgedehnt und auf die Höhe die es braucht. Wenn du jetzt die Ausrichtung so einstellst, dass im JLabel alles mittag angezeigt wird, dann dürfte dass doch das Ergebnis sein, was du willst, oder?

also das JLabel benutze ich um ein bild anzuzeigen, als überschrift.

Und die fenster groeße ist variabel, wenn die fenster größe nun zu groß ist wird es linksbündig angezeigt.

weiß nicht genau wie ich das bild zentriert ins JLabel bekomme. werd heut abend nochmal gucken.

Oder villt eine andere idee wie ich das bild oben mittig hinbekomme?

Bearbeitet von elSusto

Ich wollte erstmal deine Antwort abwarten, aber meine Idee war gleich, den oberen Bereich, der das Bild umfasst, in nem eigenen Panel zu halten und diesem wiederum dein Bild hinzuzufügen mit BorderLayout.CENTER.

Ich denk so müsste es gehen.

Vielen Dank =)

hat wunderbar funktioniert.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.