何らかの理由で、OS X で単純な SWT アプリケーションを実行すると、メニューがまったく表示されません。この問題は、私が作成した他の SWT アプリケーションでは発生しません。違うことをしている。プログラムを実行すると、画面の上部に表示されるメニューは Eclipse のものであり、たまたま私が使用している IDE です。また、Eclipse メニューが表示されている間は、クリックや応答がまったくできません。
これが現在のメニューの外観です (私が何を言おうとしているかについての混乱を避けるため):
関連するコードは次のとおりです。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.SWTResourceManager;
public class AnalyzerApp {
protected Shell shell;
Display display;
boolean thisIsAMac = SWT.getPlatform().equals("cocoa");
public static void main(String[] args) {
try {
AnalyzerApp window = new AnalyzerApp();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display.setAppName("Analyzer");
display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(832, 526);
shell.setText("Analyzer");
shell.setLayout(new FormLayout());
// Menu
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
if(thisIsAMac) menu = display.getMenuBar();
// ^ tried to fix with this, didn't change anything
MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
mntmFile.setText("File");
Menu fileMenu = new Menu(mntmFile);
mntmFile.setMenu(fileMenu);
MenuItem mntmNew = new MenuItem(fileMenu, SWT.NONE);
mntmNew.setText("New");
MenuItem mntmOpen = new MenuItem(fileMenu, SWT.NONE);
mntmOpen.setText("Open");
MenuItem mntmSave = new MenuItem(fileMenu, SWT.NONE);
mntmSave.setText("Save");
MenuItem mntmSaveAs = new MenuItem(fileMenu, SWT.NONE);
mntmSaveAs.setText("Save As");
new MenuItem(fileMenu, SWT.SEPARATOR);
MenuItem mntmImport = new MenuItem(fileMenu, SWT.NONE);
mntmImport.setText("Import");
}
}