Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening a frame on click on JMenuItem

 
pankaj saxena
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ques:
i have two menuitems : 1. Fill the form and 2. search the records.
Problem: i can't open the form when i click on 'Fill the form' menuitem, under the same MenuBar frame.

same problem is with second menuitem.

please provide me some links or your suggestions to solve this.

regards,
pankaj.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to show multiple frames you would have to use- JDesktopPane and then for each action you can hide/show corresponding JInternalFrame. You can have one Internal Frame for each of your form. I have used this a lot for my projects.
Or
You can have one JFrame and then keep changing the contents of the frame based on the Events- May be you can use one JPanel for each event- One JPanel for Fill form UI, then one JPanel for searching the records UI.

If you have some working code where you are finding problem- You can post it here. Also keep the code simple and post a working code.
 
pankaj saxena
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir,
i don't have to use Internal frames, because i want to use normal JFrame.
But, if you are saying that I have to add Internal frame to JDesktopPane , so my question is , can i add a frame to JDesktopPane? so that i can open a frame on the click of a menuitem under the same Menubar.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's better to use a modal JDialog.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pankaj saxena wrote:sir,
i don't have to use Internal frames, because i want to use normal JFrame.
But, if you are saying that I have to add Internal frame to JDesktopPane , so my question is , can i add a frame to JDesktopPane? so that i can open a frame on the click of a menuitem under the same Menubar.


Is it a requirement that you have to use JFrame only? You can't add a Window (JFrame) to a container (JDesktopPane). But you can add JInternalFrame to JDesktopPane. You actually have a JFrame which contains JDesktopPane and this in turn contains multiple JInternalFrame.
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you have two menu items, it implies you already have an existing JFrame which is visible on the screen. How have you added the actions to your menu items? Once you get the actions correct you can opt to open a new frame, use dialogs or even switch the current frame contents.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic