show image.java

来自「Show image on label in its full size」· Java 代码 · 共 41 行

JAVA
41
字号
import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

public class Temp extends JFrame{
	private JLabel label2;
	Temp(){
		super("Test");
		Container cont=getContentPane();
		//new GridLayout(0, 1)
		cont.setLayout(new FlowLayout());
		
		Icon aqua=new ImageIcon("cara1.JPG");
		label2 = new JLabel();
		/** OR
		*label2 = new JLabel(aqua);
		*and remove line 25
		*/
				//label2.setText( "Label with icon and text at bottom" );
		label2.setIcon( aqua );
				//label2.setHorizontalTextPosition( SwingConstants.CENTER );
				//label2.setVerticalTextPosition( SwingConstants.BOTTOM );
				//label2.setToolTipText( "This is label2" );
		cont.add( label2 );
		
		//setSize( 500,511 );
		setSize( 945,511 );
		setVisible(true);
	}
	public static void main(String[] args) {
		Temp m=new Temp();
		m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?