How to insert circle on secon tab on tabfolder, how to access second tab
how to draw a circle on second tab ? becouse i have, buttons on every tab, how i can sepperate them?
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");
开发者_如何学PythonButton 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();
}
}
how to draw a circle on second tab ? because i have, buttons on every tab, how i can separate them?
is it any, SWT "form designer" for free downloading?
this is filling :
GC gc = new GC(tabFolder);
Rectangle bounds = tabFolder.getBounds();
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillOval(50,50,200,200);
There aren't lot of SWT designers, but WindowBuilder pro is a good choice (and it's free).
To second part of your question, check SWT documentation for TabFolder, especially the methods
TabItem[] getItems()
- returns an array of TabItems which are the items in the receiver
TabItem[] getSelection()
- returns an array of TabItems that are currently selected in the receiver
TabItem getItem(int index)
- returns the item at the given, zero-relative index in the receiver
By those you can obtain the TabItem
you want (e.g. the second tab), and then use it for your GC
instance creation. Your circle will then be only on selected tab..
精彩评论