|
|
|
|
Re: OSX: HotKeys not working [message #734345 is a reply to message #734339] |
Fri, 07 October 2011 14:03 |
mathew.rowley Messages: 7 Registered: April 2010 |
Junior Member |
|
|
Full working example:
package com.wuntee.oter.view;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
public class Test {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
Test window = new Test();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(1, false));
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
StyledText styledText = new StyledText(composite, SWT.BORDER);
styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
addTextMenu(styledText);
}
private void addTextMenu(final StyledText styledText) {
Shell shell = styledText.getShell();
Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem item = new MenuItem(menu, SWT.NULL);
item.setText("Select All");
item.setAccelerator(SWT.MOD1 + 'A');
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
styledText.selectAll();
}
});
styledText.setMenu(menu);
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03664 seconds