• Post Reply Bookmark Topic Watch Topic
  • New Topic

Something like MDI forms in Java  RSS feed

 
Maki Jav
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am looking for something like MDI forms in Java. I mean that there is a
main application running, and on clicking the menus I could change the
frame being displayed.
eg My application has a menu "Start" which has 5 sub menus:-
1) Login
2) Main
3) Expenditure
4) Search
5) Exit
Main,Expenditure,Search
are disabled in the begining. The frame displays a Panel (blue colored). I want to display the Login Panel when the user clicks on Login.
If authenticated, he should be shown the Main frame/ panel.
Components can be removed dynamically and not added. So I cannot add various panels and display them.
I cannot add all the panels at initialization time and display the one needed by the user by using .setVisible(true) for it and setVisible(false) for all other panels.
I don't want to open new Frames and Disposing older ones each time.
One solution could be opening various dialogs but I don't want to do that either.
Any ideas?
Thanks

Maki Jav
ps: The is an example SwingSet2 in Demos folder of JDKs. But it's code is too complex for me to grasp in the short time that I had.
[ March 08, 2004: Message edited by: Maki Jav ]
 
Maki Jav
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look, I have come up with this solution!
Using JInternalFrames I can add and remove them to the mainFrame at runtime.
This way I keep one form added to the mainFrame which is a JFrame. Hence I don't get the second Internal Frame smaller in size. The user cannot minimize it nor close it, he can just move it around. That is no problem as it adjusts itself the moment mainFrame is adjusted. In short, the user can play a little.
Comments anyone?
Maki Jav
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the standard way of creating a MDI application in Java is to use a JDesktopPane and place JInternalFrames in it.
So,
JFrame frame = new JFrame();
JDesktopPane desktop = new JDesktopPane();
frame.setContentPane(desktop);
desktop.add(new JInternalFrame());
Some classnames or method names may (and probably are) incorrect here, but you get the idea. (All in javax.swing of course).
 
Maki Jav
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think that the Desktop layer is available in every JFrame and JInternal Frames are automatically added to it.
Thanx,
Maki Jav
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The previous post is incorrect.
You need to add a JDesktopPane to the JFrame (in some fashion), in order to add JInternalFrames to it (and see them). The JDesktopPane is not related to the JFrame by default by any means.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!