-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabCloseButton.java
51 lines (40 loc) · 1019 Bytes
/
TabCloseButton.java
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
/**
* @(#)TabCloseButton.java
*
*
* @author
* @version 1.00 2015/3/28
*/
/*
* Change grid layout to a border layout with a horizontal box!
*/
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JButton;
public class TabCloseButton extends JPanel
implements ActionListener
{
private JTabbedPane pane;
private Component content;
public TabCloseButton(JTabbedPane p)
{
pane = p;
int index = pane.getTabCount()-1;
content = pane.getComponentAt(index);
JLabel name = new JLabel(pane.getTitleAt(index));
JButton close = new JButton("X");
close.addActionListener(this);
setLayout(new GridLayout(1,2));
add(name);
add(close);
}
public void actionPerformed(ActionEvent e)
{
pane.remove(content);
}
}