0

This code runs fine on Windows, but not on my Macbook Air. Why? No Menu bar is visible; only the text area is visible in the output.

image

import java.awt.*;

public class Notepad extends Frame {
    public Notepad()
    {
        setTitle("Untitled-Notepad");
        TextArea t1 = new TextArea(50,80);

        MenuBar mb = new MenuBar();
        Menu file = new Menu("File");
        MenuItem n1 = new MenuItem("New");

        file.add(n1);
        mb.add(file);
        setMenuBar(mb);

        add(t1);

        setSize(350,450);
        setVisible(true);
        setLayout(null);
    }

    public static void main(String[] args) {
        Notepad n = new Notepad();
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Can you check that it doesn't appear in the system menu bar ? – Arnaud Jun 13 '17 at 15:30
  • You could use Swing OR JavaFX and probably end up with the result you're after, but to be frank, the menu bar appearing in the system menu bar is a prefered solution for Mac users – MadProgrammer Jun 13 '17 at 20:32
  • 1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. Two advantages of using Swing are that a) Swing provides components that support rich text, like `JTextPane` & b) Convenience methods like [`JTextComponent.read(..)`](https://docs.oracle.com/javase/8/docs/api/javax/swing/text/JTextComponent.html#read-java.io.Reader-java.lang.Object-) & [`write(..)`](https://docs.oracle.com/javase/8/docs/api/javax/swing/text/JTextComponent.html#write-java.io.Writer-) .. – Andrew Thompson Jun 14 '17 at 01:38
  • .. 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 3) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! – Andrew Thompson Jun 14 '17 at 01:39

1 Answers1

1

It appears in the "System Menu Bar".

System ToolBar

See, above the title bar, next to "NotePad".

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366