Java by API/org.eclipse.swt.widgets/ToolItem — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:16, 31 мая 2010
Содержание
new ToolItem(ToolBar toolBar, int style)
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MainClass {
public static void main(String[] a) {
Display d = new Display();
Shell s = new Shell(d);
final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
bar.setSize(300, 70);
bar.setLocation(0, 0);
// create images for toolbar buttons
// final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
// final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
// final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
// final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
// final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");
// create and add the button for performing an open operation
final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
// openToolItem.setImage(openIcon);
openToolItem.setText("Open");
openToolItem.setToolTipText("Open File");
// create and add the button for performing a save operation
final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
// saveToolItem.setImage(saveIcon);
saveToolItem.setText("Save");
saveToolItem.setToolTipText("Save File");
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
ToolItem: addSelectionListener(SelectionListener lis)
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MainClass {
public static void main(String[] a) {
Display d = new Display();
Shell s = new Shell(d);
final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
bar.setSize(300, 70);
bar.setLocation(0, 0);
// create images for toolbar buttons
// final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
// final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
// final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
// final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
// final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");
// create and add the button for performing an open operation
final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
// openToolItem.setImage(openIcon);
openToolItem.setText("Open");
openToolItem.setToolTipText("Open File");
// create and add the button for performing a save operation
final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
// saveToolItem.setImage(saveIcon);
saveToolItem.setText("Save");
saveToolItem.setToolTipText("Save File");
// create inner classes for SelectionListeners
class Open implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
System.out.println("Open");
}
public void widgetDefaultSelected(SelectionEvent event) {
}
}
openToolItem.addSelectionListener(new Open());
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
ToolItem: setText(String text)
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MainClass {
public static void main(String[] a) {
Display d = new Display();
Shell s = new Shell(d);
final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
bar.setSize(300, 70);
bar.setLocation(0, 0);
// create images for toolbar buttons
// final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
// final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
// final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
// final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
// final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");
// create and add the button for performing an open operation
final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
// openToolItem.setImage(openIcon);
openToolItem.setText("Open");
openToolItem.setToolTipText("Open File");
// create and add the button for performing a save operation
final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
// saveToolItem.setImage(saveIcon);
saveToolItem.setText("Save");
saveToolItem.setToolTipText("Save File");
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
ToolItem: setToolTipText(String text)
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class MainClass {
public static void main(String[] a) {
Display d = new Display();
Shell s = new Shell(d);
final ToolBar bar = new ToolBar(s, SWT.HORIZONTAL);
bar.setSize(300, 70);
bar.setLocation(0, 0);
// create images for toolbar buttons
// final Image saveIcon = new Image(d, "c:\\icons\\save.jpg");
// final Image openIcon = new Image(d, "c:\\icons\\open.jpg");
// final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg");
// final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg");
// final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg");
// create and add the button for performing an open operation
final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH);
// openToolItem.setImage(openIcon);
openToolItem.setText("Open");
openToolItem.setToolTipText("Open File");
// create and add the button for performing a save operation
final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH);
// saveToolItem.setImage(saveIcon);
saveToolItem.setText("Save");
saveToolItem.setToolTipText("Save File");
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}