-4

In my Project I am having JDesktopPane and Jmenu, in that menu I am having more internalFrames, I want to set a limit for the user so that the user can only open maximum three JinternalFrames.

I don't have any idea about how to do this, please help me.

Vegard
  • 4,802
  • 1
  • 20
  • 30

1 Answers1

3

Two things come to mind.

The first is to extend the JDesktopPane and override the addImpl method. In here, you can check the number of components on the desktop and stop adding when it reaches your limit.

The second is similar, basically, when menu activates you actionPerformed method, you check the desktop pane for how many components it contains and stop adding when you reach limit.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • +1 In the second scenario, an `Action` helps enforce the rule consistently, for [example](http://stackoverflow.com/a/11385675/230513). – trashgod Mar 12 '13 at 10:34