java swt 关闭_java-如何使用swt.TabItem添加关闭按钮?

TabFolder tabFolder = new TabFolder(composite, SWT.CLOSE);

TabItem tab1 = new TabItem(tabFolder, SWT.CLOSE);

tab1.setText("Tab 1");

TabItem tab2 = new TabItem(tabFolder, SWT.CLOSE);

tab2.setText("Tab 2");

我有一个swt.TabFolder,上面有一些swt.TabItems.

我想使用那些TabItems关闭按钮,以便我可以在运行时关闭我想要的标签.

而且我不想使用CTabFolder或CTabItem

有人可以告诉我该怎么做吗?

public DomainUI(Composite composite, TabFolder newTabFolder, boolean comingFromSelf)

{

boolean itemsDisposed = false;

TabItem[] itemsOnTabFolder = newTabFolder.getItems();

String[] namesOfItemsOnTabFolder = new String[itemsOnTabFolder.length];

if(comingFromSelf) // checking when to dispose other tabs

{

if(itemsOnTabFolder.length != 0)

{

for(int i=0; i

{

namesOfItemsOnTabFolder[i] = itemsOnTabFolder[i].getText();

itemsOnTabFolder[i].dispose();

}

itemsDisposed = true;

}

}

final Composite compositeInTab = new Composite(newTabFolder, SWT.NONE);

compositeInTab.setLayout(null);

// CREATIION OF LABELS AND TEXTFIELDS

systemCodeLabel = new Label(compositeInTab, 0);

systemCodeText = new Text(compositeInTab, SWT.BORDER);

domainNameLabel = new Label(compositeInTab, 0);

domainNameText = new Text(compositeInTab, SWT.BORDER);

organizationalUnitLabel = new Label(compositeInTab, 0);

organizationalUnitText = new Text(compositeInTab, SWT.BORDER);

organizationNameLabel = new Label(compositeInTab, 0);

organizationNameText = new Text(compositeInTab, SWT.BORDER);

systemCodeLabel.setText("System Code");

domainNameLabel.setText("Domain Name");

organizationalUnitLabel.setText("Organizational Unit");

organizationNameLabel.setText("Organization Name");

newTabFolder.addMouseListener(new MouseAdapter()

{

public void mouseUp(MouseEvent arg0)

{

TabFolder curFolder = (TabFolder)arg0.widget;

Point eventLocation = new Point(arg0.x, arg0.y);

TabItem item = curFolder.getItem(eventLocation);

if(item == null)

return;

Image image = item.getImage();

// check if click is on image

if( eventLocation.x >= item.getBounds().x + image.getBounds().x && eventLocation.x <= item.getBounds().x + image.getBounds().x + image.getBounds().width

&& eventLocation.y >= item.getBounds().y + image.getBounds().y && eventLocation.y <= item.getBounds().y + image.getBounds().y + image.getBounds().height)

{

System.out.println("Close tab");

item.dispose();

}

else

{

System.out.println("Don't close tab");

}

}

});

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值