Results 1 to 6 of 6
  1. #1
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default How can I simply disable JFrame so I can enable a new one with different settings?

    I have an always fullscreen game and I want to do something like allow the player to select which screen to display in settings, and when he applies, I figure I could just disable the JFrame somehow and then re-start everything like frame = new JFrame(/*new graphics configuration for new selected screen here*/) and apply do like setUndecorated(true), set state and other things, so re-start JFrame but completely wipe it but use the same reference of JFrame of the previous window, that's why restart and not just create another window. What code is best in this situation to use like setEnabled(false), setVisible(false) or what? just simple question.

    Kind Regards
    augustas656
    Regards
    augustas656

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    14

    Default Re: How can I simply disable JFrame so I can enable a new one with different settings

    I'm not really sure I understand your question: are you asking how to set which monitor a full-screen JFrame displays on?
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default Re: How can I simply disable JFrame so I can enable a new one with different settings

    No, how can I literally turn off a JFrame window like I would turn off the whole programe, but just the JFrame. How can I turn off the window, but keep the program running. There are methods like disable(), setEnabled(bool), dispose(), not sure which one to use.
    Regards
    augustas656

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How can I simply disable JFrame so I can enable a new one with different settings

    What did you try? Did not setVisible(false) work?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default Re: How can I simply disable JFrame so I can enable a new one with different settings

    I tried setEnabled, and it just sort of freezes it, I didn't try disable() because it's depracted, not saying you can't use it I just thought I just try other things before trying that. frame.dispose() seems to work, if that's what's the best thing to do to switch screen, because I usually define on which screen to display when defining a new JFrame with a graphics configuration.
    Regards
    augustas656

  6. #6
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default Re: How can I simply disable JFrame so I can enable a new one with different settings

    This is currently how I tested and it seems to work, not sure if this is the best way to change screens of a JFrame:

    Java Code:
    	public static void main(String[] args) {
    		GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    		GraphicsConfiguration s1 = env.getScreenDevices()[0].getDefaultConfiguration();
    		GraphicsConfiguration s2 = env.getScreenDevices()[1].getDefaultConfiguration();
    		int w1 = (int) s1.getBounds().getWidth();
    		int h1 = (int) s1.getBounds().getHeight();
    		int w2 = (int) s2.getBounds().getWidth();
    		int h2 = (int) s2.getBounds().getHeight();
    		
    		JFrame frame;
    		
    		frame = new JFrame(s1);
    		frame.setSize(w1, h1);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    		frame.setUndecorated(true);
    		frame.setVisible(true);
    		
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			e.printStackTrace();
    		}
    		
    		frame.dispose();
    		
    		frame = new JFrame(s2);
    		frame.setSize(w2, h2);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    		frame.setUndecorated(true);
    		frame.setVisible(true);
    		
    		try {
    			Thread.sleep(3000);
    		} catch (InterruptedException e) {
    			e.printStackTrace();
    		}
    		
    		frame.dispose();
    	}
    Regards
    augustas656
    Regards
    augustas656

Similar Threads

  1. Enable or disable encryption in a JPasswordField
    By Pojahn_M in forum AWT / Swing
    Replies: 1
    Last Post: 05-26-2012, 09:35 PM
  2. Enable/Disable tabs based on user
    By R S Reddy in forum New To Java
    Replies: 2
    Last Post: 08-30-2011, 08:57 AM
  3. How to Enable and Disable JtextField on Selection of Checkbox
    By deshmukh.niraj04 in forum New To Java
    Replies: 1
    Last Post: 04-11-2011, 12:26 PM
  4. Please help : JSP enable/disable button
    By kalyana in forum New To Java
    Replies: 3
    Last Post: 03-24-2011, 05:06 PM
  5. use javascript to enable/disable hyperlinks
    By sauravsinha in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 04-22-2010, 06:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •