Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How to set disable JFrame but keep enable JMenubar?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to set disable JFrame but keep enable JMenubar?

    ¡Hello!

    I'm programming a simple game; I want to disable the main window (JFrame) when the game is over and only allow to use the menu bar in order to create new game, change level, quit or whatever, but disable all the rest of the window. The behaviour would be like the minesweeper of windows.

    I've tried using
    mainWindow.setEnabled(false)
    but it disables all the window belong to the menu bar, this happen even I use
    menuBar.setEnabled(true)
    after that.

    All suggestions are welcome.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    Are there specific components on the window you want to disable? What container is used by the window to hold the components?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    There are 3 panels each one with differents components: buttons, table, textarea, etc. in addition to the menu bar.
    The window use an opaque JPanel which contains the other three panels.

    This is the attributes for the main window:
    	//view components<
    	private JPanel contentPane;
     
    	private NavigationPanel navigationPanel;
    	private RobotPanel robotPanel;
    	private InstructionsPanel instructionsPanel;
     
    	private JMenuBar menuBar;
     
    	//>
     
    	//model components
    		private  Model modelReference;
    		//>
     
    	private JOptionPane dialog;

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    Have you tried disabling the container that holds the components or the individual components?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    Yes I have, but it doesn't disable anything.
    I think that is because the panel are lightweight but the JFrame is heavyweight, and java API tells this:

    public void setEnabled(boolean b)
    Enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

    Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.

    Note: Disabling a heavyweight container prevents all components in this container from receiving any input events. But disabling a lightweight container affects only this container.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    Can you make a small complete program that compiles, executes and shows the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How to set disable JFrame but keep enable JMenubar?

    You can intercept mouse clicks on the glass pane.

    Read this page

    I don't know exactly what type of components you want to disable, but you could also programmatically ignore clicks on the components you want to disable, or disable the specific components. ...depending on what and how many etc.

Similar Threads

  1. Problem with JMenuBar(Solved)
    By albin1228 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 4th, 2013, 04:08 PM
  2. Menus will not appear in JMenubar
    By mwardjava92 in forum AWT / Java Swing
    Replies: 8
    Last Post: March 19th, 2013, 04:02 PM
  3. Replies: 2
    Last Post: October 31st, 2012, 01:07 AM
  4. JMenuBar disappears half the time when using a certain line of code?
    By !Marcus in forum Java Theory & Questions
    Replies: 2
    Last Post: December 26th, 2011, 04:05 PM
  5. Replies: 33
    Last Post: May 25th, 2011, 06:59 AM