1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.vci.client.ui.swing.components;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import com.vci.client.ui.swing.VCISwingUtil;
 
 
public class TabTitleComponent extends VCIJPanel {
    /**
     * 
     */
    private static final long serialVersionUID = 4109281420551018722L;
    private VCIJLabel lbl = new VCIJLabel();
    private VCIJButton btnClose = VCISwingUtil.createVCIJButton("close", "", "关闭", "");
    private JClosableTabbedPane tab = null;
    private Component tabComponent = null; 
    public TabTitleComponent(JClosableTabbedPane tab, Component tabComponent){
        this.tab = tab;
        this.tabComponent = tabComponent;
        setLayout(new BorderLayout(5, 0));
        add(lbl, BorderLayout.CENTER);
        this.setOpaque(false);
        lbl.setOpaque(false);
        setButtonProperty(btnClose);
        btnClose.setIcon(new CloseTabIcon(null));
        add(btnClose, BorderLayout.EAST);
        btnClose.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                closeTab();
            }
        });
    }
 
    private void closeTab(){
        int index = this.tab.indexOfTabComponent(this);
        if(index < 0) return;
        this.tab.removeTabAt(index);
    }
    
    public void setTitle(String title){
        lbl.setText(title);
    }
    
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        setButtonProperty(btnClose);
    }
    
    private void setButtonProperty(VCIJButton btn){
        btn.setOpaque(false);
        btn.setFocusable(false);
        btn.setBorderPainted(false);
        btn.setBorder(null);
    }
 
    public JClosableTabbedPane getTab() {
        return tab;
    }
 
    public void setTab(JClosableTabbedPane tab) {
        this.tab = tab;
    }
 
    public Component getTabComponent() {
        return tabComponent;
    }
    
    public void setTabComponent(Component tabComponent) {
        this.tabComponent = tabComponent;
    }
}