scrollingimage.java
来自「java编程开发技巧与实例的编译测试通过的所有例程」· Java 代码 · 共 61 行
JAVA
61 行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ScrollingImage extends JFrame implements ActionListener
{
private JLabel imageLabel = new JLabel();
private JButton quit = new JButton("Quit");
//private String fileName = "scenery999.jpg";
private String fileName = "dsc04120_mthumb.jpg";
public ScrollingImage()
{
super("Scrolling Image");
ImageIcon icon = new ImageIcon(fileName);
imageLabel.setIcon(icon);
JScrollPane scrollingLabel = new JScrollPane(imageLabel);
scrollingLabel.setPreferredSize(new Dimension(670, 300));
JPanel info = new JPanel(new GridLayout(3, 1));
info.add(new JLabel("Image Name: " + fileName));
info.add(new JLabel("Image Width: " + icon.getIconWidth()));
info.add(new JLabel("Image Height: " + icon.getIconHeight()));
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollingLabel, info);
split.setDividerSize(10);
split.setOneTouchExpandable(true);
split.setContinuousLayout(true);
//JTabbedPane tabs = new JTabbedPane();
//tabs.addTab("Image", scrollingLabel);
//tabs.addTab("Info", info);
JPanel buttons = new JPanel(new FlowLayout());
buttons.add(quit);
getContentPane().add("Center", split);
//getContentPane().add("Center", scrollingLabel);
getContentPane().add("South", buttons);
quit.addActionListener(this);
//setLocationRelativeTo(null);
validate();
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
public static void main(String args[])
{
try
{
String lf_wind = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
String lf_unix = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
String lf_java = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(lf_java);
}
catch (Exception e)
{
System.err.println("Exception: " + e);
}
ScrollingImage si = new ScrollingImage();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?