私は基本的なプログラムを作成してスイングGUIを使用して学習しています。何らかの理由で私がプログラムを実行するとフレームに表示されません。フレームに設定されているにもかかわらずSwing GUIにJavaメニューバーが表示されない
public class GUITest {
private static int windowWidth = 500;
private static int windowHeight = 500;
private static JFrame frame;
private static JMenuBar menuBar;
public static void main(String[] args){
build();
}
private static void build(){
windowGen();
menuGen();
}
private static void windowGen(){
JFrame frame = new JFrame();
frame.setLayout(null);
frame.setSize(windowWidth,windowHeight);
frame.setVisible(true);
}
private static void menuGen(){
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem menuFileExit = new JMenuItem("Exit");
menuFile.add(menuFileExit);
menuBar.add(menuFile);
frame.setJMenuBar(menuBar);
}
}
なぜこのようなことがありますか?
のレイアウトを定義することではありません –
'setVisible(true)'は最後に呼び出す必要があります。なぜなら、すべてのコンポーネントがレイアウトされているからです。メニューバーを変更する必要がある場合は、少し異なります。 – markspace
ahhhhありがとうございました=] –