Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Miromancer

Thread: Dialogs extending JDialog - entwine them with the root pane

  1. #1
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Dialogs extending JDialog - entwine them with the root pane

    Hi there.

    Sorry for the confusing title, it is difficult to describe in just a few words.
    The issue is this: I coded some JDialogs and when I switch windows (e.g. to another program and back) the rootPane is no longer visible, only the dialog. Is there a way to keep displayed both at all times?

    Thanks in advance
    Mirek

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    Impossible to guess with so little information. Could be a case of a wrong approach to custom painting, or failure to respect Swing's single threaded rule, or using a defective JRE like GNU/GCJ (non-)Java, or just about anything.

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    OK, here is simplified version of one of the dialogs in question:

    Java Code:
    import java.awt.Dimension;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.WindowConstants;
    
    
    public class TestDialog extends JDialog {
        JButton btnOk = new JButton("Show choices");
        Dimension dim;
         
        public TestDialog(){
        super();
        setModal(true);
        setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        }
        
      
        public void getChosenTerritory(){
        displayChoices();
         dispose();
        }
         
        /**
         * Builds UI and fills the task text
         * and Capital choices
         */
        private void displayChoices(){
            getContentPane().add(btnOk);
            pack();
            final int RESERVE = 50;
            int width =  RESERVE;
            int height = getPreferredSize().height;
            dim = new Dimension(width, height);
            setMinimumSize(dim);
            setBounds(MainRiskForm.centerBounds(dim));
            setVisible(true);
        }
     }
    on the main form I call:

    Java Code:
     
    
    TestDialog dial = new TestDialog();
                    
    dial.getChosenTerritory();
    Is it alright this way?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    I gave you a link to the SSCCE web page in the expectation that you would go through it and not post uncompilable, non-executable snippets. It appears I was wasting my time.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    Your code doesn't explain the misbehavior your describing. I agree with Darryl in that the best way for us to be able to help you is if you can post a *minimal* program that compiles and runs and demonstrates your problem. If we can't reproduce your behavior, it's much less likely that we'll be able to help you. On the other hand, we don't want to be drowning in code, most of it unrelated to the problem. This whittling down the program to expose the misbehavior will take quite a bit of work on your part, but it won't be work wasted, and in fact in all likelihood following through with this exercise will likely lead you to discovering the problem and its solution without our help.

  6. #6
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    Sorry, here is the complete SSCCE project:

    https://dl.dropbox.com/u/108807093/SSCCE.7z

  7. #7
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    So, I believe I made a sufficiently simple program. Expected behaviour is this:

    when I click the button and the dialog shows itself, I run Firefox for example, and when I switch back to the program I would like to see the mainform too.
    But all I get is the modal dialog.

    Can you see what is wrong? Can I fix it or do I need to use different approach than modal JDialog?

  8. #8
    Miromancer is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Dialogs extending JDialog - entwine them with the root pane

    I have figured it out, thanks for the guidance. I suppose it is most useful to crack it up yourself.
    All I needed to do was attach a parentComponent.

    Have a nice bugfree day
    Fubarable likes this.

Similar Threads

  1. Using Dialogs to display text
    By tipz in forum AWT / Swing
    Replies: 3
    Last Post: 05-10-2011, 12:10 PM
  2. Custom graphics on dialogs, etc.
    By trader5050 in forum New To Java
    Replies: 1
    Last Post: 11-24-2010, 08:29 AM
  3. Communicating between Dialogs and Frames
    By frejon26 in forum Threads and Synchronization
    Replies: 1
    Last Post: 05-23-2010, 06:49 AM
  4. How do I get all dialogs?
    By zenteo in forum AWT / Swing
    Replies: 6
    Last Post: 03-08-2010, 11:01 PM
  5. Passing data between dialogs
    By Wintery in forum New To Java
    Replies: 7
    Last Post: 01-02-2009, 06:35 AM

Tags for this Thread

Posting Permissions

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