我正在使用jtabbedpane,我正在尝试设置一个选项卡的关闭按钮,但不会丢失它的标题!
注意:
这是我的代码:
if(nronda==(rondas.size()-2)){
String titulo = "MF"+node.toString();
GestorJanelas.addTab(titulo, dc);
GestorJanelas.setSelectedIndex(GestorJanelas.getTabCount()-1);
GestorJanelas.setTabComponentAt(GestorJanelas.getSelectedIndex(), new BtnFechar(GestorJanelas,titulo));
}else{
步骤:
以下是我的BtnFechar类的代码:
public class BtnFechar extends JButton implements ActionListener {
JTabbedPane pane;
String titulo;
public BtnFechar(JTabbedPane p, String titulo) {
this.pane = p;
this.titulo = titulo;
int size = 17;
JLabel label = new JLabel();
label.setText(titulo);
add(label);
setPreferredSize(new Dimension(size, size));
setToolTipText("close this tab");
//Make the button looks the same for all Laf's
setUI(new BasicButtonUI());
//Make it transparent
setContentAreaFilled(false);
//No need to be focusable
setFocusable(false);
setBorder(BorderFactory.createEtchedBorder());
setBorderPainted(false);
//Close the proper tab by clicking the button
addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae) {
int i = pane.getSelectedIndex();
if (i != -1) {
pane.remove(i);
}
}
任何人都可以帮我这个或告诉我在标签上插入标题的方法吗?
当程序运行时会发生这种情况:http://imgur.com/DOnS6rH
检查选项卡名称,当我在那里添加一个关闭按钮时它们会消失!
注意:当前选中的标签在其所有标题和内容上都没有按钮