如何在第二个标签上绘制圆圈?因为我有,每个标签上的按钮,我怎么能隔离它们?
package shelllab;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = new Display();
final Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
shell.setText("ShellExample");
shell.setSize(700,500);
final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
Menu bar = new Menu (shell, SWT.BAR);
shell.setMenuBar (bar);
MenuItem f1 = new MenuItem (bar, SWT.CASCADE);
f1.setText ("&Файл");
MenuItem f2 = new MenuItem (bar, SWT.CASCADE);
f2.setText ("&О программе");
Menu s1 = new Menu (shell, SWT.DROP_DOWN);
f1.setMenu (s1);
MenuItem item = new MenuItem (s1, SWT.PUSH);
MenuItem item2 = new MenuItem (s1, SWT.PUSH);
MenuItem item3 = new MenuItem (s1, SWT.PUSH);
final TabFolder tabFolder = new TabFolder (shell, SWT.BORDER);
Rectangle clientArea = shell.getClientArea ();
tabFolder.setLocation (clientArea.x, clientArea.y);
tabFolder.setSize(400, 500);
for (int i=0; i<3; i++) {
TabItem item1 = new TabItem (tabFolder, SWT.NONE);
}
f2.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
MessageDialog.openWarning(shell, "Внимание", "Демонстрация работы с shell - лаба №2");
}
});
item.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
//System.exit(0);
GC gc = new GC(tabFolder);
Rectangle bounds = tabFolder.getBounds();
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillOval(50,50,200,200);
}
});
item2.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
tabFolder.getItem(0).setText("This is example 1");
Button b1 = new Button(tabFolder, SWT.PUSH);
b1.setSize(180, 40);
b1.setText("Выбрать цвет для tabfolder2");
b1.setLocation(5, 25);
Button b12 = new Button(tabFolder, SWT.PUSH);
b12.setSize(180, 40);
b12.setText("Выбрать цвет для tabfolder3");
b12.setLocation(5, 80);
final Combo c = new Combo(tabFolder, SWT.READ_ONLY);
c.setBounds(250, 35, 100, 20);
String items[] = { "red", "blue", "green"};
c.setItems(items);
final Combo c2 = new Combo(tabFolder, SWT.READ_ONLY);
c2.setBounds(250, 90, 100, 20);
String items2[] = { "red", "blue", "green"};
c2.setItems(items2);
b1.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
//tabFolder.setForeground(blue);
if (c.getText().equals("red"))
{
//tabFolder.getItem(2).setControl(tabFolder);
}
}
});
//tabFolder.getItem(0).setData(b1);
}
});
item.setText("Выход Ctrl+Q");
item.setAccelerator (SWT.MOD1 + 'Q');
item2.setText("Пример №1 Ctrl+1");
item2.setAccelerator (SWT.MOD1 + '1');
item3.setText("Пример №2 Ctrl+2");
item3.setAccelerator (SWT.MOD1 + '2');
tabFolder.getItem(0).setText("Example1");
tabFolder.getItem(1).setText("Example2");
tabFolder.getItem(2).setText("Example3");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
如何在第二个标签上绘制圆圈?因为我有,每个标签上的按钮,我如何分开它们?
是免费下载的SWT“表单设计师”吗?
这是填补:
GC gc = new GC(tabFolder);
Rectangle bounds = tabFolder.getBounds();
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillOval(50,50,200,200);
答案 0 :(得分:1)
没有很多SWT设计师,但WindowBuilder pro是一个不错的选择(并且它是免费的)。
要问题的第二部分,请检查SWT documentation for TabFolder,尤其是方法
TabItem[] getItems()
- 返回一个TabItem数组,它们是接收器中的项目
TabItem[] getSelection()
- 返回当前在接收方中选择的TabItem数组
TabItem getItem(int index)
- 返回接收器中给定零相对索引的项
您可以获取所需的TabItem
(例如第二个标签),然后将其用于GC
实例创建。您的圈子将仅在选定的标签上显示..