Skip to content

Instantly share code, notes, and snippets.

@skrb
Last active Sep 26, 2019
Embed
What would you like to do?
Swing Image View Demo
package net.javainthebox.imageview;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Main {
public Main() {
JPanel root = new JPanel();
root.setLayout(new BorderLayout());
JLabel label = new JLabel(new ImageIcon("イメージファイル"));
root.add(label, BorderLayout.CENTER);
JFrame frame = new JFrame();
frame.add(root);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(630, 450));
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Main());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment