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.

Image Width/Height

Empfohlene Antworten

Veröffentlicht

Hallo,

ich würde gerne ein in Java eingebundenes Bild möglichst stufenlos vergrößern verkleinern können, per JSlider.

Momentan habe ich das so, dass ich 10x das gleiche Bild in verschiedenen Größen habe und er jedes mal nen neues lädt, wenn der Slider verschoben wird.


    private static JLabel imageLabel = new JLabel();

    public void karte(final Layout layout) {

	imageLabel.setIcon(icon9);


	//Bild wird aufs Scrollpane geadded

	final JScrollPane scrollPane = new JScrollPane(

		JScrollPane.VERTICAL_SCROLLBAR_NEVER,

		JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

	scrollPane.getViewport().add(imageLabel);

	scrollPane.setBounds(50, 10, 700, 500);

	layout.pKarte.add(scrollPane, BorderLayout.CENTER);

Es gibt ja ne Methode:

imageLabel.getIcon().getIconHeight()

aber setIconHeight() scheint es nicht zu geben, gibt's da ne andere Möglichkeit für?

Überschreibe die Paint-Methode deiner Anzeigefläche (z.B. eines Panels).

Dann kannst du das zeichnen des Images selbst machen.

graphics.drawImage(image, startX, startY, breite, höhe, this);


public class ViewField extends JPanel{

  private Image image; 


  public ViewField(Image image){

      this.image = image;

  }


  public void paint(Graphics g){

     g.drawImage(image, 0, 0, getWidth(), getHeight(), this);

  }

}

Wenn du diese Klasse verwendest brauchst dann nur noch die Größe des ViewFields verändern und das Image wird automatisch verkleiner/vergrößert angezeigt.

Wichtig ist allerdings, dass du dem ViewField eine möglichst große Version des Images gibst, ansonsten wirds beim vergößern natürlich pixelig.

Bearbeitet von speedi

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.