this my internal code
i get error java.lang.IllegalArgumentException at desktop.add(data.getInstance());
please help me figure what went wrong and how to fix it
reference = i am using eclipse and windowbuilder
Dave Tolls wrote:Bit of a guess here, but on the second click of the button you would be adding the same JInternalFrame to the desktop.
It's already in there, so I can imagine that might cause issues.
well my aim to limit this same frame to show more than once, i try to add singleton at internalframe and
call it and put it on desktop, is there wrong with my step
Campbell Ritchie wrote:Why are you trying to create singletons in the first place? And why are you using double checked locking? That isn't the correct way to implement a singleton.
my aim is to prevent mutiple window of this internalframe, so i try to use singleton for this purpose, please correct me if i'm wrong
Paul Clapham wrote:
cliff perkasa wrote:my aim is to prevent mutiple window of this internalframe
That doesn't answer the question, why do you want to have a singleton? What problems arise when you have more than one instance of the InternalFrame?
well i want to prevent the desktop from overcrowded with same instances, and that internal frame is for view table, also if i create another internalframe to modify(edit, insert, delete), i want to make that instance to be updated.
about singleton, i find singleton can prevent mutiple instance of same class when googling, so i try to use it for my problem
Dave Tolls wrote:But, by the time you click the button the second time, you've already added it.
There's no where that removes the frame, so that means you are adding it twice...which apparently you don't want to do.
ok i get it now, but how to fix it? if i not wrong, remove internalframe and add new but how to know that same internalframe already exist at desktop
cliff perkasa wrote:well i want to prevent the desktop from overcrowded with same instances
Then write code which doesn't do that. Making a singleton isn't going to affect what your GUI-creating code does... except that it might throw an exception if you try to add the instance in more than one place on the screen. Actually it looks like that might be what's actually happening, but you don't seem to be satisfied with that solution to your problem. And rightly so because it isn't a solution to your problem.
Paul Clapham wrote:And I'm like everyone else answering here, it looks like. You already have an InternalFrame in your GUI as soon as it starts up, so you don't need to add another one ever. You've got a perfectly good method to refresh the contents of that InternalFrame, so just call that method when you need it update.
thanks for the advice, so i try another way
i change my maincode:
at internal frame:
sorry now is not about singleton topic but to limit only one same instance.
i try to limit internalframe by checking it visible or not, if not add new one else call refresh method and set internalframe to hide when close but the code above still not working
what lacking on my code
1. Create the InternalFrame and add it to the GUI when you create and initialize the GUI. Probably it won't have any data in it at this point.
2. When you want to show new data in the InternalFrame, call the method which you put there for that purpose.
I don't understand what you're saying about closing something, either. Seems to me you should just close the GUI when you're finished using it, I don't see why you need to close the InternalFrame separately.