为什么我无法看到菜单栏的所有元素?

问题描述:

有时候我的菜单上有两个元素,有时候都是,但如果元素不可见,我需要调整窗口大小。如果我调整窗口的大小,就会出现元素。为什么?为什么我无法看到菜单栏的所有元素?

这是我的代码:

//Class TextEditor start 
public class TextEditor extends JFrame{ 

private JMenuBar menuBar; 
private JMenu file,edit,format,view,help; 
private JMenuItem newFile; 
private JMenuItem exit; 

//Main method start 
public static void main(String[] args){ 
    try{ 
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    }catch (Exception e){ 

    } 
    new TextEditor(); 
} 
//Main class end 


//Class constructor start 
private TextEditor(){ 
     super("Untitled"); 
     sendUI(this); 
     sendMenuBar(); 
    } 
//Class constructor end 

//Menu bar start// 
public void sendMenuBar(){ 
    menuBar = new JMenuBar(); 
    setJMenuBar(menuBar); 

    //File menu and Items 
    file = new JMenu(" File "); 
    newFile = new JMenuItem("New"); 
    exit = new JMenuItem("Exit"); 
    menuBar.add(file); 
    file.add(newFile); 
    file.add(exit); 

    //Edit menu and items 
    edit = new JMenu(" Edit "); 
    menuBar.add(edit); 

    //Format menu and items 
    format = new JMenu(" Format "); 
    menuBar.add(format); 

    //View menu and items 
    view = new JMenu(" View "); 
    menuBar.add(view); 

    //Help menu and items 
    help = new JMenu(" Help "); 
    menuBar.add(help); 
} 


private void sendUI(TextEditor texteditor) { 
    texteditor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    texteditor.setSize(700,400); 
    texteditor.setLocationRelativeTo(null); 
    texteditor.setVisible(true); 
} 

} 
//Class TextEditor end 

当出现错误:

enter image description here

后,我调整窗口的大小:

enter image description here

+2

你可以在sendMenuBar之后调用senUI。 – StackFlowed 2014-08-29 12:54:14

+0

谢谢@Aeshang。这是问题所在。 – 2014-08-29 12:56:07

+0

如果它适合您,请将答案标记为正确。 – StackFlowed 2014-08-29 15:42:56

你需要调用senUI在sendMenuBar之后。