-2

I am new to Java. I have programming experience on other programming languages , especially in PowerBuilder. I am writing a Java application with many forms and reports. I want to have a menu common for all forms and reports (any window on my application).

I thought I could create a basic mainframe with the menu on it and the open any other window inside this main frame. I can't figure this out , only with internal frames but this is not what I want.

I made my JMenuBar, I put it on JPanel and then I put panel on a maximized JFrame I called mainframe. Any window from menu bar opens in front of mainframe frame. When I click on mainframe any open window goes back of course, focus is on the mainframe.

I wrote a MouseListener for panel which brings any open window toFront except mainframe of course. That seems to make the job but I have to write the same listener for the menu bar and this has the disadvantage of windows "flashing" any time they are coming to front.

My questions are:

  • What is the way you work with menu bars?
  • Do I have to put menu bar to any form I create?
  • How can I have a main frame (maybe maximized) with the menu bar on it always on back and any other window opens in front of this frame?

What I really need is a main frame with menu for my application and everything happens inside this frame.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
kpk
  • 119
  • 3
  • 12
  • 1
    code will speak better then words here, I guess. – YoungHobbit Jun 01 '16 at 06:33
  • From what i´ve read you add the `JMenu` to the `JPanel`, but it should be added to the `JFrame` – SomeJavaGuy Jun 01 '16 at 06:34
  • 2
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 01 '16 at 06:41
  • 1
    *"only with internal frames but this is not what I want."* Why ***not*** use a `JDesktopPane` & `JInternallFrame`s? – Andrew Thompson Jun 01 '16 at 06:43
  • *"How can I have a main frame (maybe maximized) with the menu bar on it always on back and any other window opens in front of this frame?"* If the frame(s) were instead dialog(s) that passed `mainFrame` as the parent, that would happen automatically. – Andrew Thompson Jun 01 '16 at 06:45
  • I added the JMenuBar to a JPanel and then edded the JPanel to a JFrame because I wanted to write a mouselistener on JPanel which brings toFront any active window except the mainframe. – kpk Jun 01 '16 at 06:52
  • "Why not use a JDesktopPane & JInternallFrames? " I think I have more flexibility with JForms but I will give a try to JInternallFrames The solution with mouselistener who brings any window front seems to work but I have to write a mouse listener for jmenubar too. Is there any way to do this? – kpk Jun 01 '16 at 08:01
  • 1
    I'd take a closer look at [How to Use Internal Frames](https://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html) – MadProgrammer Jun 01 '16 at 09:23
  • Tip: Add @YoungHobbit (or whoever, the `@` is important) to *notify* the person of a new comment. *"I think I have more flexibility with JForms"* Stop talking like your IDE. There is no such thing in the J2SE as a `JForm` - if you mean a `JFrame` then **write that!** – Andrew Thompson Jun 04 '16 at 03:51

1 Answers1

0

I will work with InternaFrames finally

Thanks a lot

kpk
  • 119
  • 3
  • 12