This discussion is archived
7 Replies Latest reply: Sep 26, 2012 6:01 AM by gimbal2 RSS

persistent (modeless?) dialog

942608 Newbie
Currently Being Moderated
Greetings,

I need to create a dialog box that will remain on screen throughout the life of the application, and to which the program can write text messages that scroll as more 'n more are added.

I've been through tutorial exercises, and I've tried to find this by searching forums, but somehow I come up with nothing.

Please help the poor almost-newb.

Thanks

Chris Lanz
lanzcc@potsdam.edu
  • 1. Re: persistent (modeless?) dialog
    800268 Expert
    Currently Being Moderated
    What problem do you have exactly?

    You says you did the tutorial, so you know how to show a non-modal dialog.
    And if you can follow that tutorial, surely you you know how to save a reference to an object (the dialog) and call a method on it (to add extra text to it)?
  • 2. Re: persistent (modeless?) dialog
    942608 Newbie
    Currently Being Moderated
    Hello, thanks for responding

    I am making some structural error. I assumed that I should use the modeless dialog (that is, extend "dialog" and set the Modality) but everything I tried failed.
    I'll go now and try again, now confident that it's modeless dialogs I should use, and I'll figure out exactly what questions to ask....

    One of the problems is, the tutorials include everything in one file. My failure may arise when I try to move the various bits of code to main.

    Thanks again - I hope I don't need to use anymore of your time.

    chris lanz
  • 3. Re: persistent (modeless?) dialog
    gimbal2 Guru
    Currently Being Moderated
    The trouble with a modeless dialog is that it blocks access to all other windows until you close it - that's not what you want. You can create a modal dialog and make it stay on top by calling setAlwaysOnTop(true).That approach has its own issues, especially when you're using custom painting; the last time I attempted to use a dialog that stayed on top as soon as it was over a component that did custom painting, the entire component was repainted on every little change in stead of only the region that was dirty. That created some major performance problems with scrolling.

    Me, I'd just open a separate undecorated JFrame and don't care of it is on top or not to be honest, especially if its only some sort of message log. Perhaps you can even leave the frame decorated and provide the user with the ability to hide the message window (it doesn't have to close, you can just make it invisible so you can keep sending messages to it).
  • 4. Re: persistent (modeless?) dialog
    800268 Expert
    Currently Being Moderated
    clanz wrote:
    One of the problems is, the tutorials include everything in one file. My failure may arise when I try to move the various bits of code to main.
    Since you didn't include your moved tutorial code, no one here can comment on it and point out the problems.
    gimbal2 wrote:
    The trouble with a modeless dialog is that it blocks access to all other windows until you close it
    No, a modal dialog blocks access; a non-modal one does not.
    You can create a modal dialog and make it stay on top by calling setAlwaysOnTop(true).
    A dialog (modal or not) stays on top of its parent window (if set through a constructor), which is probably what the OP wants.
    That created some major performance problems with scrolling.
    Sounds more like inefficient custom painting to me and very unlikely to be fixed by switching from a dialog to a frame (unless you mean to have that frame behind your custom painting, which again is not what I think the OP wants.
  • 5. Re: persistent (modeless?) dialog
    gimbal2 Guru
    Currently Being Moderated
    Walter Laan wrote:
    gimbal2 wrote:
    The trouble with a modeless dialog is that it blocks access to all other windows until you close it
    No, a modal dialog blocks access; a non-modal one does not.
    Crud, I always mix them up. Sorry!
    Sounds more like inefficient custom painting to me and very unlikely to be fixed by switching from a dialog to a frame (unless you mean to have that frame behind your custom painting, which again is not what I think the OP wants.
    Yeah I believe I'm spewing more lies: it was the result of using an internal frame, not a dialog/external frame. The fact that the entire component rerendered was by design and documented and not any kind of bug, so I changed the way I did it (dropping the use of internal frames).

    Note to self: must not rely on vague memories.

    Edited by: gimbal2 on Jun 11, 2012 7:39 AM
  • 6. Re: persistent (modeless?) dialog
    942608 Newbie
    Currently Being Moderated
    Thanks for the discussion, everybody, it solved my problem!
  • 7. Re: persistent (modeless?) dialog
    gimbal2 Guru
    Currently Being Moderated
    Ha ha, better late than never :)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points