Skip to content

Instantly share code, notes, and snippets.

@arwagner
Created October 20, 2015 23:58
Show Gist options
  • Save arwagner/32ce2e3ec5d9d23041d9 to your computer and use it in GitHub Desktop.
Save arwagner/32ce2e3ec5d9d23041d9 to your computer and use it in GitHub Desktop.
Something I'm not understanding about resizing labels
package com.andrewwagner.chess.study;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) throws IOException{
JFrame frame = new JFrame();
final JPanel panel = new JPanel();
final JLabel label = new JLabel();
panel.add(label);
frame.add(panel);
frame.pack();
frame.setVisible(true);
Image image = ImageIO.read(new File("/Users/andrew/Downloads/Programming.jpg"));
label.setIcon(new ImageIcon(image));
label.revalidate();
panel.revalidate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment