package com.han;
import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class JTabbedPane_1 extends JFrame {
/**
*
*/
private static final long serialVersionUID = -4058924020221196702L;
public JTabbedPane_1() {
// TODO Auto-generated constructor stub
final JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
// TODO Auto-generated method stub
int selectedIndex = tabbedPane.getSelectedIndex();
String title = tabbedPane.getTitleAt(selectedIndex);
System.out.println(title);
}
});
URL resource = JTabbedPane_1.class.getResource("/images/Luxun.jpg");
BufferedImage imageScaled = null;
try {
String[] readerFormatNames = ImageIO.getReaderFormatNames();
for (String name : readerFormatNames) {
System.out.print(name + "\t");
}
System.out.println();
String[] writerFormatNames = ImageIO.getWriterFormatNames();
for (String name : writerFormatNames) {
System.out.print(name + "\t");
}
System.out.println();
BufferedImage in = ImageIO.read(resource);
imageScaled = ImageScale.scale(in, 0.1, 0.1, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ImageIcon imageIcon = new ImageIcon(imageScaled);
JLabel tabLabelA = new JLabel("选项卡A");
JLabel tabLabelB = new JLabel("选项卡B");
JLabel tabLabelC = new JLabel("选项卡C");
tabbedPane.addTab("选项卡A", imageIcon, tabLabelA, "点击查看选项卡A");
tabbedPane.addTab("选项卡B", imageIcon, tabLabelB, "点击查看选项卡B");
tabbedPane.addTab("选项卡C", imageIcon, tabLabelC, "点击查看选项卡C");
tabbedPane.setSelectedIndex(2); // 初始化界面时默认的是选中第一个选项卡即 index = 0
tabbedPane.setEnabledAt(0, false);
getContentPane().add(tabbedPane, BorderLayout.CENTER);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JTabbedPane_1 frame = new JTabbedPane_1();
frame.setTitle("选项卡面板");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.pack();
frame.setBounds(100, 100, 500, 300);
}
}
JTabbedPane_1
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:Java JTree_5
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java Swing JTabbedPane:选项卡组件
创建套接字:create(端口号,socket类型,ip地址(null表示接收
java javaswing 开发语言 结点 选项卡