List of usage examples for org.eclipse.swt.widgets Button getLocation
public Point getLocation()
From source file:ControlSizeLocation.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.PUSH); shell.setSize(260, 120);/*w w w .j av a2 s .c o m*/ shell.open(); System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:ControlBounds.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Button button = new Button(shell, SWT.PUSH); button.setBounds(20, 20, 200, 20);/* w w w . j a v a 2 s . c o m*/ shell.setSize(260, 120); shell.open(); System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:org.eclipse.swt.examples.controlexample.Tab.java
/** * Creates and opens the "Listener selection" dialog. *//*from ww w . ja va 2 s. c om*/ void createListenerSelectionDialog() { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); dialog.setText(ControlExample.getResourceString("Select_Listeners")); dialog.setLayout(new GridLayout(2, false)); final Table table = new Table(dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); GridData data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 3; table.setLayoutData(data); for (int i = 0; i < EVENT_INFO.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(EVENT_INFO[i].name); item.setChecked(eventsFilter[i]); } final String[] customNames = getCustomEventNames(); for (int i = 0; i < customNames.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(customNames[i]); item.setChecked(eventsFilter[EVENT_INFO.length + i]); } Button selectAll = new Button(dialog, SWT.PUSH); selectAll.setText(ControlExample.getResourceString("Select_All")); selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); selectAll.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { items[i].setChecked(true); } for (int i = 0; i < customNames.length; i++) { items[EVENT_INFO.length + i].setChecked(true); } })); Button deselectAll = new Button(dialog, SWT.PUSH); deselectAll.setText(ControlExample.getResourceString("Deselect_All")); deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); deselectAll.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { items[i].setChecked(false); } for (int i = 0; i < customNames.length; i++) { items[EVENT_INFO.length + i].setChecked(false); } })); final Button editEvent = new Button(dialog, SWT.PUSH); editEvent.setText(ControlExample.getResourceString("Edit_Event")); editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); editEvent.addSelectionListener(widgetSelectedAdapter(e -> { Point pt = editEvent.getLocation(); pt = e.display.map(editEvent, null, pt); int index = table.getSelectionIndex(); if (getExampleWidgets().length > 0 && index != -1) { createEditEventDialog(dialog, pt.x, pt.y, index); } })); editEvent.setEnabled(false); table.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int fields = 0; int index = table.getSelectionIndex(); if (index != -1 && index < EVENT_INFO.length) { // TODO: Allow custom widgets to specify event info fields = (EVENT_INFO[index].settableFields); } editEvent.setEnabled(fields != 0); } @Override public void widgetDefaultSelected(SelectionEvent e) { if (editEvent.getEnabled()) { Point pt = editEvent.getLocation(); pt = e.display.map(editEvent, null, pt); int index = table.getSelectionIndex(); if (getExampleWidgets().length > 0 && index != -1 && index < EVENT_INFO.length) { createEditEventDialog(dialog, pt.x, pt.y, index); } } } }); new Label(dialog, SWT.NONE); /* Filler */ Button ok = new Button(dialog, SWT.PUSH); ok.setText(ControlExample.getResourceString("OK")); dialog.setDefaultButton(ok); ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); ok.addSelectionListener(widgetSelectedAdapter(e -> { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_INFO.length; i++) { eventsFilter[i] = items[i].getChecked(); } for (int i = 0; i < customNames.length; i++) { eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked(); } dialog.dispose(); })); dialog.pack(); /* * If the preferred size of the dialog is too tall for the display, * then reduce the height, so that the vertical scrollbar will appear. */ Rectangle bounds = dialog.getBounds(); Rectangle trim = dialog.computeTrim(0, 0, 0, 0); Rectangle clientArea = display.getClientArea(); if (bounds.height > clientArea.height) { dialog.setSize(bounds.width, clientArea.height - trim.height); } dialog.setLocation(bounds.x, clientArea.y); dialog.open(); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:org.eclipse.swt.examples.controlexample.Tab.java
/** * Append the Set/Get API controls to the "Other" group. *//* www. j a v a 2s. com*/ void createSetGetGroup() { /* * Create the button to access set/get API functionality. */ final String[] methodNames = getMethodNames(); if (methodNames != null) { final Button setGetButton = new Button(otherGroup, SWT.PUSH); setGetButton.setText(ControlExample.getResourceString("Set_Get")); setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); setGetButton.addSelectionListener(widgetSelectedAdapter(e -> { if (getExampleWidgets().length > 0) { if (setGetDialog == null) { setGetDialog = createSetGetDialog(methodNames); } Point pt = setGetButton.getLocation(); pt = display.map(setGetButton.getParent(), null, pt); setGetDialog.setLocation(pt.x, pt.y); setGetDialog.open(); } })); } }
From source file:CustomControlExample.java
/** * Append the Set/Get API controls to the "Other" group. *//* ww w .j ava 2s .c o m*/ void createSetGetGroup() { /* * Create the button to access set/get API functionality. */ final String[] methodNames = getMethodNames(); if (methodNames != null) { Button setGetButton = new Button(otherGroup, SWT.PUSH); setGetButton.setText(ControlExample.getResourceString("Set_Get")); setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); setGetButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = (Button) e.widget; Point pt = button.getLocation(); pt = e.display.map(button, null, pt); createSetGetDialog(pt.x, pt.y, methodNames); } }); } }