• Post Reply Bookmark Topic Watch Topic
  • New Topic

Open new window from menu click  RSS feed

 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, I'm pretty much a novice w/ swing and awt...

Anyway, I'm working on a small application which currently consists simply of a JFrame w/ several menus. For one of the choices in one of the menus I would like to open a new window which will have just a couple of components in it. I'm familiar w/ using an anonymous inner class to create a new ActionListener and perform some action. But I'm not sure how to go about creating a new window when someone clicks on a menu choice.
I would appreciate it if someone could point me in the right direction.


Thanks,
Mike
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
You can create your class wich will exteds JFrame. Put on it all the necessary components. In the end of constructor call such methods as setSize(int, int), setLocation(int, int), show().
Now in your menuitem ActionListener in the actionPerformed(ActionEvent e)
method create an instance of your class. Something like this:



Or if you need new Window wich is modal you can use the JDialog instead of JFrame. See documentation about JDialog.
 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I've never used JDialog, but that looks interesting so I think I'll give it a try and see how it works out.

Thanks again,
Mike
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!