imageicon

Scale the ImageIcon automatically to label size

天大地大妈咪最大 提交于 2019-11-26 00:20:39
问题 On my JFrame, I am using the following code to display an image on the Panel : ImageIcon img= new ImageIcon(\"res.png\"); jLabel.setIcon(img); I would like to \"auto-size\" the picture in the label. Indeed, sometimes the image size is only few pixel, sometimes well more. Is there a way to set the size of the label, and then to autosize the image in the label? 回答1: This is a tricky question. You highlight the fact that you are using a JLabel to show the image, which is the standard way of

How can I save the state of my program and then load it?

给你一囗甜甜゛ 提交于 2019-11-25 23:49:58
问题 I\'m trying to save and reload the state of my Swing program, which in this case is a Minesweeper game. My code for the board is below. package mines; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Random; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; public class Board extends JPanel { public static void main (String[] args) {}