Results 1 to 9 of 9
  1. #1
    jchinson is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default disabling and re-enabling a jframe

    I have a root window with two buttons on it. When one of those buttons is pressed I want the root window to be disabled while a new window pops up. After I'm finished with that window I want the root window to be re-enabled. Here is how I'm trying to do it.

    Java Code:
    	addBtn.addActionListener(
    				new ActionListener() {
    					public void actionPerformed(ActionEvent e) {
    						frame.setEnabled(false);
    						addKid();
    						frame.setEnabled(true);
    					}
    				});
    This doesn't disable the root window at all. If i comment out the setEnabled line it will disable the root window, but I can't interact with it once I'm done with the second window.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    This button simply sets enabled, does something else and then sets enabled back.

    So if it's enabled initially it will disable and re enable it in a very short amount of time(nanoseconds most likely), you should probably have a button to disable it and one to enable it, or use a timer to put a pause in.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default

    After I'm finished with that window
    What does the addKid() method do?
    Your call to addKid() is on Swing's EDT thread. That could effect how Swing responds since you are using its thread.

  4. #4
    jchinson is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default

    This button simply sets enabled, does something else and then sets enabled back.
    Yes, the function addKid() opens another JFrame. I figured that frame.setEnabled(true) wouldn't be called until I was done with the addKid() function. How would I go about putting a pause in?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default

    That sounds like you need a modal dialog. It will pause the execution of the calling code until the dialog returns.

  6. #6
    jchinson is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default

    Any way I could do it without dialogs? My addkid() function brings up a new JFrame with a bunch of JTextFields that are used to enter information. Is it possible to use JTextFields in a dialog?

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default

    I think you can put about any component into a JDialog. There is a link from the JDialog API doc to a tutorial on How to Make Dialogs.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by jchinson View Post
    Any way I could do it without dialogs? My addkid() function brings up a new JFrame with a bunch of JTextFields that are used to enter information. Is it possible to use JTextFields in a dialog?
    Yes it's possible and as Norm states, advisable. This is what dialogs excel at. Know that a JDialog can hold a GUI that's every bit as complex as a JFrame.

  9. #9
    jchinson is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Enabling Javascript
    By drewsonoffergus in forum Networking
    Replies: 1
    Last Post: 08-06-2011, 09:42 PM
  2. enabling keystrokes
    By elieN in forum AWT / Swing
    Replies: 7
    Last Post: 05-28-2011, 07:29 PM
  3. disabling JFrame's response to spacebar
    By gib65 in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2010, 05:38 PM
  4. repeated enabling disabling icon (card flipping)
    By luckylandie in forum AWT / Swing
    Replies: 3
    Last Post: 07-24-2010, 12:01 AM
  5. Replies: 0
    Last Post: 07-07-2008, 05:35 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
  •