Results 1 to 6 of 6
- 05-11-2012, 08:52 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Click on jmenuitem open the jinternalframe..
Hi...
I m created one simple frame with menu in netbeans.
and also created jinternalframe in the same package.
whenever i clicked on menuitem Its open Jinternalframe manytimes..
for example : File menu -> File1(Menuitem)
when i click on file1 its open jinternalframe. again i click on file1 its open the new jinternalframe..
so i don't want to open new internalframe when the same frame is open.
This is my code to open jinternal frame on mouse clicked on menu.
help me to open only 1 frame at a time when the jinternalframe1 are open on clicking on menuitem its doesn't open once again on click same menuitem.XML Code:private void Jinternalframe1_MenuMouseClicked(java.awt.event.MouseEvent evt) { Jinternalframe1 jn = new Jinternalframe1(); this.desktopPane.add(jn); jn.show(); }
Thanx
mcajavaprogramerLast edited by mcajavaprogramer; 05-11-2012 at 08:58 AM.
- 05-16-2012, 06:41 AM #2
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Re: Click on jmenuitem open the jinternalframe..
There is no-body who have this solution about this question..?
- 05-16-2012, 07:16 AM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: Click on jmenuitem open the jinternalframe..
What about creating a JInternalFrames class member variable. Then, in the mouse click function, only create the internal frame if the member variable is null.
Java Code:Jinternalframe1 jn = null; private void Jinternalframe1_MenuMouseClicked(java.awt.event.MouseEvent evt) { if (jn == null) { jn = new Jinternalframe1(); this.desktopPane.add(jn); jn.show(); } }
- 05-16-2012, 08:24 AM #4
Re: Click on jmenuitem open the jinternalframe..
First, the correct listener for a JMenuItem is ActionListener, not MouseListener.
A better programming idiom is to disable the menu item when the internal frame is opened, and enable it when the internal frame is closed. You would use an InternalFrameListener for that, probably extending InternalFrameAdapter.
Another possibility, if you want to give the user the option to close the internal frame from the menu, is to use a JCheckBoxMenuItem.
Read the API for those classes and follow any links to the Oracle tutorials on 'How to Use ...'
db
edit: You've probably already been told this, but the NetBeans (or any other) visual designer is categorically not a beginners' tool. Unless you aim to make a career out of Swing GUI design (not likely, now that JavaFX has started to take over the market) it's just not worht the time and effort to learn all its quirks. That time and effort is much better spent in reading tutorials and learning how to code a Swing GUI by hand.Last edited by DarrylBurke; 05-16-2012 at 08:26 AM.
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-16-2012, 12:55 PM #5
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
- 05-16-2012, 12:56 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
How to open .ods file on button click event
By Anagha in forum New To JavaReplies: 15Last Post: 07-08-2012, 09:10 PM -
Can we open .ods file on button click event..............
By Anagha in forum AWT / SwingReplies: 6Last Post: 03-19-2011, 03:24 AM -
Open the file by mouse click
By Chika in forum New To JavaReplies: 3Last Post: 09-19-2010, 11:44 PM -
How we can open a file with a click in button
By kostinio in forum AWT / SwingReplies: 2Last Post: 11-01-2009, 04:46 PM -
how to click a jbutton and open an url
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:44 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks