-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathButtonTabComponent.java
More file actions
76 lines (67 loc) · 2.58 KB
/
ButtonTabComponent.java
File metadata and controls
76 lines (67 loc) · 2.58 KB
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
package burp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonTabComponent extends JPanel {
private ExtractorMainTab extractorMainTab;
private int tabNum;
public ButtonTabComponent(ExtractorMainTab extractorMainTab, int tabNum) {
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.extractorMainTab = extractorMainTab;
this.tabNum = tabNum;
setOpaque(false);
//make JLabel read titles from JTabbedPane
JLabel label = new JLabel(Integer.toString(tabNum));
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
JButton button = new TabButton();
add(button);
}
private class TabButton extends JButton implements ActionListener {
public TabButton() {
int size = 15;
setPreferredSize(new Dimension(size, size));
setToolTipText("close this tab");
setText("x");
//Make it transparent
setContentAreaFilled(false);
//No need to be focusable
setFocusable(false);
setBorder(BorderFactory.createEtchedBorder());
setBorderPainted(false);
//Making nice rollover effect
//we use the same listener for all buttons
addMouseListener(buttonMouseListener);
setRolloverEnabled(true);
//Close the proper tab by clicking the button
addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
int index = extractorMainTab.getIndexOfTabComponent(ButtonTabComponent.this);
if (index != -1) {
extractorMainTab.removeTab(index);
extractorMainTab.removeExtractor(tabNum);
ExtractorMainTab.tabsRemoved++;
}
}
}
private final static MouseListener buttonMouseListener = new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
Component component = e.getComponent();
if (component instanceof AbstractButton) {
AbstractButton button = (AbstractButton) component;
button.setBorderPainted(true);
}
}
public void mouseExited(MouseEvent e) {
Component component = e.getComponent();
if (component instanceof AbstractButton) {
AbstractButton button = (AbstractButton) component;
button.setBorderPainted(false);
}
}
};
}