随笔-19  评论-128  文章-1  trackbacks-0
可关闭的TabbedPane结构:


测试代码:

package cn.demo.test;

import java.awt.Component;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;

/**
 * Test
 * 
@author Tom
 *
 
*/
public class TestDemo {

    
public static void main(String[] args) {
        
try {
            String feel 
= UIManager.getSystemLookAndFeelClassName();
            UIManager.setLookAndFeel(feel);
        } 
catch (Exception e) {
            e.printStackTrace();
        } 
        
        JFrame frame 
= new JFrame();
        frame.setTitle(
"可关闭Tab测试");
        frame.setSize(
300400);
        frame.setLocationRelativeTo(
null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        TabbedPane tabbedPane 
= new TabbedPane();
        tabbedPane.setCloseButtonEnabled(
true);
        tabbedPane.addTab(
"测试一"nullnew JLabel("测试一"));
        tabbedPane.addTab(
"测试二"nullnew JLabel("测试二"));
        tabbedPane.addTab(
"测试三"nullnew JLabel("测试三"));
        tabbedPane.addTab(
"测试四"nullnew JLabel("测试四"));
        tabbedPane.addTabbedPaneListener(
new TabbedPaneListener(){
            @Override
            
public void allTabsRemoved() {
                
// TODO Auto-generated method stub
                
            }
            @Override
            
public boolean canTabClose(Tab tab, Component component) {
                
// TODO Auto-generated method stub
                return false;
            }
            @Override
            
public void tabAdded(Tab tab, Component component, int index) {
                
// TODO Auto-generated method stub
                
            }
            @Override
            
public void tabRemoved(Tab tab, Component component, int index) {
                
// TODO Auto-generated method stub
                System.out.println("close");
            }
            @Override
            
public void tabSelected(Tab tab, Component component, int index) {
                
// TODO Auto-generated method stub
                
            }
        });
        
        frame.add(tabbedPane);
        frame.setVisible(
true);
    }
    
}

 测试效果:

     

源码下载:TabbedPane.rar

发表人: Tom


posted on 2010-10-24 16:44 obpm 阅读(6113) 评论(2)  编辑  收藏 所属分类: 控件

评论:
# re: Java Swing 可关闭的TabbedPane 2010-10-26 11:34 | 蛋疼
感谢分享!  回复  更多评论
  
# re: Java Swing 可关闭的TabbedPane[未登录] 2010-10-26 21:35 | NIcholas
不错,支持一下  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: