簡體   English   中英

為什么我看不到菜單欄的所有元素?

[英]Why I cant see all the elements for my menubar?

有時菜單上有2個元素,有時除了菜單元素不可見外,其他所有元素都需要調整窗口大小。 如果我調整窗口大小,則會顯示元素。 為什么?

這是我的代碼:

//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

當錯誤出現時:

在此處輸入圖片說明

調整窗口大小后:

在此處輸入圖片說明

您需要在sendMenuBar之后調用senUI。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM