TabbedPaneDemo
- package swing.tabbedpane;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ButtonGroup;
- import javax.swing.ImageIcon;
- import javax.swing.JCheckBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JTabbedPane;
- import javax.swing.JToggleButton;
- import javax.swing.SwingConstants;
- import javax.swing.SwingUtilities;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- /*2015-7-12*/
- public class TabbedPaneTest {
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- JFrame frame = new TabbedPaneFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- frame.setLocationRelativeTo(null);
- }
- });
- }
- }
- class TabbedPaneFrame extends JFrame {
- private static final long serialVersionUID = -7748936498904415868L;
- private static final int DEFAULT_WIDTH = 400;
- private static int DEFAULT_HEIGHT = 400;
- private JTabbedPane tabbedPane;
- public TabbedPaneFrame() {
- setTitle(getClass().getSimpleName());
- setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
- tabbedPane = new JTabbedPane();
- ImageIcon icon = new ImageIcon(getClass().getResource("/swing/tabbedpane/blue-ball.gif").getPath());
- tabbedPane.addTab("Mercury", icon, null);
- tabbedPane.addTab("Venus", icon, null);
- tabbedPane.addTab("Earth", icon, null);
- tabbedPane.addTab("Mars", icon, null);
- tabbedPane.addTab("Jupiter", icon, null);
- tabbedPane.addTab("Saturn", icon, null);
- tabbedPane.addTab("Uranus", icon, null);
- tabbedPane.addTab("Neptune", icon, null);
- tabbedPane.addTab("Pluto", null, null);
- final int plutoIndex = tabbedPane.indexOfTab("Pluto");
- JPanel plutoPanel = new JPanel();
- plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING));
- JToggleButton plutoCheckBox = new JCheckBox();
- plutoCheckBox.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- tabbedPane.remove(plutoIndex);
- }
- });
- plutoPanel.add(plutoCheckBox);
- tabbedPane.setTabComponentAt(plutoIndex, plutoPanel);
- // add(tabbedPane, "Center");
- add(tabbedPane, BorderLayout.CENTER);
- tabbedPane.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- if (tabbedPane.getSelectedComponent() == null) {
- int n = tabbedPane.getSelectedIndex();
- loadTab(n);
- }
- }
- });
- loadTab(0);
- JPanel buttonPanel = new JPanel();
- ButtonGroup buttonGroup = new ButtonGroup();
- JRadioButton wrapButton = new JRadioButton("Wrap tabs");
- wrapButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
- }
- });
- buttonPanel.add(wrapButton);
- buttonGroup.add(wrapButton);
- wrapButton.setSelected(true);
- JRadioButton scrollButton = new JRadioButton("Scroll tabs");
- scrollButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
- }
- });
- buttonPanel.add(scrollButton);
- buttonGroup.add(scrollButton);
- add(buttonPanel, BorderLayout.SOUTH);
- }
- protected void loadTab(int n) {
- String title = tabbedPane.getTitleAt(n);
- String filePath = getClass().getResource("/swing/tabbedpane/" + title.toLowerCase() + ".png").getPath();
- ImageIcon planetIcon = new ImageIcon(filePath);
- tabbedPane.setComponentAt(n, new JLabel(planetIcon));
- tabbedPane.setIconAt(n, new ImageIcon(getClass().getResource("/swing/tabbedpane/red-ball.gif").getPath()));
- }
- }
TabbedPaneDemo的更多相关文章
- menu JPopupMenu JTabbedPane
菜单是GUI中最常用的组件,菜单不是Component类的子类,不能放置在普通容器中,不受布局管理器的约束,只能放置在菜单栏中. 菜单组件由菜单栏 (MenuBar).菜单(Menu)和菜单项(Men ...
随机推荐
- 将svnkit转成dlls时的问题
未处理 System.TypeInitializationException Message="“org.tmatesoft.svn.core.internal.wc.DefaultSVNO ...
- SQLServer 复制和数据库镜像 具体配置部署
SQLserver 能够把镜像和复制同一时候部署,结合了两方的高可用性.能够使数据库得到更好的高可用性和容灾的保证. 关于镜像:f=255&MSPPError=-2147217396" ...
- C++习题 虚函数-计算图形面积
C++习题 虚函数-计算图形面积 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 122 Solved: 86 [cid=1143&pid=6 ...
- HttpApplication处理对象与HttpModule处理模块
HttpApplication处理对象与HttpModule处理模块 (第三篇) 一.HttpApplication对象简述 在HttpRuntime创建了HttpContext对象之后,HttpRu ...
- Tomcat6 Session建立机制简要
底: 测试部门做压力测试, 结果没多久新闻,出现OutOfMemory. 查找原因,通过监视工具,查找StandardSession(org.apache.catalina.session.Stan ...
- JAVA insert() 插入字符串 reverse() 颠倒 delete()和deleteCharAt() 删除字符 replace() 替换 substring() 截取子串
insert() 插入字符串 StringBuffer insert(int index,String str) StringBuffer insert(int index,char ch) Stri ...
- 主要的核心思想是取cookie然后发查询请求,不需要浏览器做代理(转)
需求是催生项目和推进项目的不竭动力. 背景: 最近,因为媳妇要做个B超检查,想着去大医院查查应该更放心,所以就把目标瞄准在A医院.早已耳闻A院一号难求万人空巷,所以把所有能接触到的机会都看了一遍,线下 ...
- 简单fcgi程序
1.头文件 #include <fcgi_stdio.h> 2.while(FCGI_Accept()>=0)//这里进入循环,前台每请求一次fcgi服务,就循环一次 循环内处理: ...
- WPF之Binding深入探讨--Darren
1,Data Binding在WPF中的地位 程序的本质是数据+算法.数据会在存储.逻辑和界面三层之间流通,所以站在数据的角度上来看,这三层都很重要.但算法在3层中的分布是不均匀的,对于一个3层结构的 ...
- 【HTML+CSS】(1)基本语法
HTML基金会 <em>他强调标签,<strong>加粗标签 <q>短文本引用.<blockquote>长文本引用,这两个标签会让文字带双引號. 空 ...