Execute code after show() in a Modal JDialog

Is there any way of executing a piece of code after a Modal JDialog's show() method ? I tried to run the code using SwingUtilities.invokeLater to no use. Any ideas ?
Thanks !

Thanks Jamie !
Adding a new thread wasn't required. I found the solution in some forum. The main issue was to get focus to a textfield in JDialog along with displaying a JPopupMenu against it. I could get the focus in but the popup wasn't showing. In brief this is what solved it.
Assuming JTextField is testField. I add this listener to the textField just before calling JDialog.show().
<code>
     private FocusListener fListen = new FocusListener()
          public void focusGained(FocusEvent e)
               // showPop() logic
          public void focusLost(FocusEvent e)
               testField.removeFocusListener(fListen);
               testField.requestFocus();
</code>

Similar Messages

  • Adf valueChangeListener autosubmit=true, execute code after update model

    Hello.
    I'm working with the valueChangeListener and autosubmit="true". I'll try to explain my situation
    with an example.
    jsp:
    <af:form>
         <af:panelForm>
              <af:inputText
                   id="value1"
                   label="Value1"
                   value="#{index.myObject.value1}"
                   autoSubmit="true"
                   valueChangeListener="#{index.changeListener1}"/>
              <af:inputText
                   id="value2"
                   label="Value2"
                   value="#{index.myObject.value2}"/>
         </af:panelForm>
    </af:form>
    backing:
    public class Index {
        private MyObject myObject;
        public Index() {
            myObject = new MyObject();
        public void changeListener1(ValueChangeEvent valueChangeEvent){
              doSomethingWithMyObject(myObject);
        // ... get/set of myObject
    MyObject:
    public class MyObject {
        private String value1;
        private String value2;
        public MyObject() {}
         //getters/setters...
    }In the line doSomethingWithMyObject(myObject) i need myObject with the actual values in the user form.
    in the example above, the first time the page is rendered and shows the inputs
    if the user captures something in the 1st input and then hits the tab to go to the other input
    the valueChangeEvent is fired, and the code in "index.changeListener1" executed, but at this moment
    the model (myObject) hasn't been updated with the data that the user entered (Validation Phase).
    So i need a way to execute my code called from the "valueChangeEvent" but after the model has been updated
    Some notes about my problem:
         - The doSomethingWithMyObject(myObject) could update data in myObject
         - About binding="#{x.y}":
         I know i can use the binding attribute in the tag <af:inputText binding="#{x.y}"> and then in the code of
         the changelistener the binded component always have the most recent value from the user,
         but i cant' use that, the method needs a MyObject instance.
         - I don't think create a new instance of MyObject and populate it every time the event fires is a good way
         - doSomethingWithMyObject" is a black box, so i don't know what is going to do with myObject
         - In my problem there are more than 2 inputs there will be N components M listeners.
    What I'm trying:
         PhaseListener:
         I have been implementing a solution with a PhaseListener like
         public void afterPhase(PhaseEvent phaseEvent) {
              // just after UPDATE_MODEL_VALUES phase
              FacesContext f = FacesContext.getCurrentInstance();
            Index i = (Index) f.getApplication().createValueBinding("#{index}").getValue(f);
              // at this point the model is updated
              doSomethingWithMyObject(i.getMyObject);
         public PhaseId getPhaseId() {
            return PhaseId.UPDATE_MODEL_VALUES;
              this works but i don't know if this is the answer according to this post (unanswered at this time):
              http://forums.oracle.com/forums/thread.jspa?threadID=611643
         says something about that PhaseListener is not thread safe and blocks the application with more
         than 1 user.
         A wrapper:
         using the controls binded to the backing
         public class Index {
              private MyObject myObject;
              private CoreInputText inputValue1;
              private CoreInputText inputValue2;
              //listener
              //getters/setters
         }     make a wraper like
         public class MyObjectW {
             private Index index; // wrap the backing index
             public MyObjectW(Index index) {
                 this.index = index;
             public String getValue1(){
                 return (String) index.getInputValue1().getValue();
             public String getValue2(){
                 return (String) index.getInputValue2().getValue();
             public void setValue1(Object v){
                 index.getInputValue1().setValue(v);
             public void setValue2(Object v){
                 index.getInputValue2().setValue(v);
        }and then call in the index backing:
    doSomethingWithMyObject( new MyObjectW(this)); so it will access to the most actual values from user at the valueChangeEvent
    But i really would like some way to execute my code called from the "valueChangeEvent" but after the model has been updated
    so i dont need to wrap or implement PhaseListener
    what do you think, what do you suggest, have any solution or a way to do what I'm trying?
    thank you for your help...
    Message was edited by:
    akanewsted

    Hello Frank, thanks for the response.
    When you say
    "If you need an updated object in this listener then you can update it from the value change listener as well"
    you mean i can update the object by myself with the value from getNewValue()? or is there another way
    to call to update the models at this time ?
    I know i have the methods "getOldValue()" and "getNewValue()" in the "ValueChangeEvent" but what if i need
    the actual value from the user in other control than the one that fires the event
    example
    Two inputs:
    in the input1 the user enters some data
    in the input2 when some data is entered it fires valueChangeListener (autosubmit=true)
    in that case what if i need the value the user just entered in the input1 in the valueChangeListener of
    the input2.
    In general the app I'm working must do:
    dynamically generate the controls in the form (inputs, selects etc)
    Attach the control values to a model ( <af:inputText value=#{model.x}"/>
    sometimes execute some script when a value change in a control (valueChangeListener)
    those scripts uses the model (and needs to be an updated model)
              script = " if (value2 = 'xyz') then value1='abc'; return true;";
    if the model is not updated
    the script will use old values and will be wrong
    or if the script change some value in the model, when the update model phase occurs the value from
    the script is lost.
    that's why i need to work directly with the model and not the values in the ValueChangeEvent
    Is there a way to use something like an action in the change of a control value?
    that way the code will execute in the invoke application phase, can this be done ?
    how i can execute code in the invoke application when a valueChangeEvent occurs ?
    hope this help to explain more my situation.
    Thank you for your help and time.

  • How to execute code after JSF startup?

    Hello,
    I need to execute some initialization code after JSF startup, so I cannot do the usual ServletContextListener trick, as that runs before JSF is completely initialized. Any ideas?
    Kind regards,
    Ulrich

    I can think of one way to do this (which might be a bit cumbersome for what you are trying to do) : use the Spring framework's web integration classes.
    You can specifiy a context listener in your web.xml :
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    That way, Spring will load an ApplicationContext, and in that context you can specify a Spring bean that will be instantiated at application startup, which will perform whatever logic you need to do.
    More info here :
    http://static.springframework.org/spring/docs/2.0.x/reference/webintegration.html

  • When i execute code, it shows "Record 1/?" and takes too much of time to execute.

    Hi all,
    I have s form with push_button (SEND TO BACKUP).
    For this push button - SEND TO BACKUP, i have coded the below for Trigger - WHEN BUTTON PRESSED.
    DECLARE
      CNT NUMBER;
      TEMPDATE DATE;
    CURSOR C1 IS SELECT MAT_DESC, FRAME, FSIZE,    POLES, NUMS, DRG_NO,    RM_WT, FIN_WT, RATE,    FRAMENAME, FTYPE, CHND_DATE,RATESOFPO
    FROM RMC_INACTIVE_MAT_RATES_MP;
    BEGIN
      FOR I IN C1 LOOP
       SELECT COUNT(CHND_DATE) INTO CNT FROM RMC_INACTIVE_MAT_RATES_MP_PREV WHERE CHND_DATE=I.CHND_DATE;
      IF CNT > 1 or cnt=1 THEN
       MESSAGE('INACTIVE MATERIAL RATES FOR MEGAPACK  ALREADY EXIST IN BACKUP WITH THIS DATE ');
      MESSAGE(' ');
      Raise Form_Trigger_Failure;
      end if;
    end loop;
      FOR I IN C1 LOOP
      INSERT INTO RMC_INACTIVE_MAT_RATES_MP_prev(MAT_DESC, FRAME, FSIZE, POLES, NUMS, DRG_NO,    RM_WT, FIN_WT, RATE,    FRAMENAME, FTYPE, CHND_DATE,
      RATESOFPO )
      VALUES(I.MAT_DESC, I.FRAME, I.FSIZE, I.POLES, I.NUMS, I.DRG_NO,    I.RM_WT, I.FIN_WT, I.RATE,    I.FRAMENAME, I.FTYPE, I.CHND_DATE,I.RATESOFPO  );
      END LOOP;
      COMMIT  ;
      MESSAGE('DATA HAS SENT SUCCESSFULLY ');
      MESSAGE(' ',NO_ACKNOWLEDGE);
    END;
    It is working but with lot of delay, it takes too much of time.
    After i run this form & as i press the button, it shows "Record 1/?" in the below and it takes almost 5 mins to execute completely and dhow the message.
    Can you tell why is it showing "Record 1/?" below ???
    How to reduce the delay??
    Thank You.
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    If you want to suppress the message shown in status you can set the sevearity like :system.message_level          := '20';
    Can you change your code like
    :system.message_level          := '20'; --- To suppress the default messages
    DECLARE
      CNT NUMBER;
      TEMPDATE DATE;
    CURSOR C1 IS SELECT MAT_DESC, FRAME, FSIZE,    POLES, NUMS, DRG_NO,    RM_WT, FIN_WT, RATE,    FRAMENAME, FTYPE, CHND_DATE,RATESOFPO
    FROM RMC_INACTIVE_MAT_RATES_MP;
    BEGIN
      FOR I IN C1 LOOP
       SELECT COUNT(CHND_DATE) INTO CNT FROM RMC_INACTIVE_MAT_RATES_MP_PREV WHERE CHND_DATE=I.CHND_DATE;
      IF cnt >= 1 THEN
       MESSAGE('INACTIVE MATERIAL RATES FOR MEGAPACK  ALREADY EXIST IN BACKUP WITH THIS DATE ');
      MESSAGE(' ');
      Raise Form_Trigger_Failure;
      end if;
    end loop;
      FOR I IN C1 LOOP
      INSERT INTO RMC_INACTIVE_MAT_RATES_MP_prev(MAT_DESC, FRAME, FSIZE, POLES, NUMS, DRG_NO,    RM_WT, FIN_WT, RATE,    FRAMENAME, FTYPE, CHND_DATE,
      RATESOFPO )
      VALUES(I.MAT_DESC, I.FRAME, I.FSIZE, I.POLES, I.NUMS, I.DRG_NO,    I.RM_WT, I.FIN_WT, I.RATE,    I.FRAMENAME, I.FTYPE, I.CHND_DATE,I.RATESOFPO  );
      END LOOP;
      COMMIT  ;
      MESSAGE('DATA HAS SENT SUCCESSFULLY ');
      MESSAGE(' ',NO_ACKNOWLEDGE);
    END;

  • Executing code after a transition has finished

    Hi,
    Is there any kind of language construct in JavaFX to allow a certain block of code to be executed after a transition has finished? Or do I have to pause the current thread with sleep() or similar?
    The ideal would be something like this, but of course such a thing like onComplete does not exist AFAIK:
    FadeTransition {node: selectedNode duration: 1s fromValue: 1 toValue: 0 onComplete: executeThis()}.play();

    Hello,
    By "delete node" you mean delete it from scene? This example works for me:
    var stage: Stage = Stage {
        width: 250
        height: 250
        scene: Scene {
            content: [
                text = Text {
                    layoutY: 30
                    opacity: 0.0
                    content: "Example transition"
                Button {
                    layoutY: 70
                    text: "Click me"
                    action: function() {
                       FadeTransition {
                            node: text
                            fromValue: 0.0
                            toValue: 1.0
                            duration: 200ms
                            action: function() {
                                delete text from stage.scene.content;
                        }.play();
    }Saša

  • Acrobat looses windows focus after showing a wxWidgets modal dialog

    Here's a code sample:
         AVWindow dlgWindow = AVWindowNewFromPlatformThing(AVWLmodal, NULL, NULL, gExtensionID, dlg->GetHWND());
        AVAppBeginModal(dlgWindow);
        dlg->ShowModal();                                   // dlg is a wxDialog*
        AVWindowDestroy(dlgWindow);
        AVAppEndModal();
    This works in so far as the wxWidgets window is modal with respect to Acrobat, however when we do AVAppEndModal Acrobat does not get the windows focus back.  In fact some other open application gets it instead, which is a problem for the end user.
    If I take away the Begin and End, I do not get the focus problem, however I do not get the modal nature either.
    Any ideas on how to solve this?
    Thanks
    Simon

    Hi,
    I see this too.
    The only workaround I found is to use Windows api to find the Acrobat window and switch back to it maually. There is a flicker, but at least the user is back in his original window.
    I can confirm this behaviour on Wndows XP, Vista, and 7 in Acrobat 8, Acrobat 9 and Acrobat 10.
    Simple code that works for me:
    void SetWinFocusBackToAA()
        #ifdef WIN_PLATFORM   
            if (gHWND) SetForegroundWindow(gHWND); //AA 8 MDI
            else
                HWND AAhwnd = FindWindow(L"AcrobatSDIWindow", NULL);
                if (AAhwnd) SetForegroundWindow(AAhwnd);
        #endif
    I do not see such a problem on Mac OS X.
    I suspect the problem lies in setting correct parent for the modal window, but I have not been able to find one (for some years now).
    Also this does not happen when the modal wx dialog is a child of another wx windows (a modeless window).
    Polda

  • Execute code after Spry region redrawn / added to DOM

    Hi,
    I'm integrating my Spry event data with a YUI calendar.
    Everything is working and event dates are highlighted on the YUI calendar.  There is one last thing I wish to do which is to update the YUI calendar with a Spry Tooltip.  The div regions for the tooltip text are generated dynamically by via a Spry repeating region.  What I am failing to do is attach the tooltips to the YUI calendar after the Spry repeating region has been added to the docuement DOM. So the Spry Tooltip function cannot find the ID of the tooltips.
    I have a dataset observer "onpostload" which seems to fire when the data is loaded but before the document dom has been updated by Spry.  How can I ensure I wait for Spry to update the region and hence DOM with the new data before triggering the tooltip code?
    Cheers
    Phil

    You got different kind of observers in Spry Data.
    - Dataset observers:
         datasetname.addObserver( observer )
    - Spry Region Observers:
         Spry.Data.Region.addObserver( 'region-id', observer );
    The dataset observers send out notifications when there is a event happening inside the Spry Data Sets. The one you mentioned is part of this (onPostLoad). These are great to monitor your data changes, but in your case. You don't want to use these.
    The Spry region observers respond to events that are happening in side the region. For example onPreUpdate, this event is called when the region is about to generate / insert new markup in to your region. But you also got the onPostUpdate. This is the observer you are looking for, it gets called once the region has re-generated its code / html. It gets fired directly after the new HTML has been inserted.
    Small note about the region observers, these require a id= attribute. This id attribute must be placed on the same element as the spry:region. To learn, and read more about the observers i would like to referrer you to this article:
    Data Set and Region Overview
    Its rather large, but using the browser build in find function you should be able to locate the sections about the observers
    Hopes this helps,

  • Execute javascript after update and submit in Skillbuilders Modal Page

    Hi,
    I'm editing, say, list of my employees in a tabular form opened in Skillbuilders Modal Page.
    I have to execute same javascript code after the changes in the tabular form have been submitted.
    I've tried using a Dynamic Action fired on Page Load, but that gets executed before the update is completed.
    Does anyone have an idea how to accomplish this?
    Thank you!

    Thank you for your answers.
    Yes, I'm trying to execute javascript code on the child page, the modal one.
    Basically, there's a button on my parent page which opens the modal page. The modal page has buttons Cancel, Delete and Save. Clicking Save button submits the changes and if there are errors, errors are shown and we stay on the modal page.
    My modal pages are all of fixed dimensions and if there are errors, I have to adjust the other regions (adjust their height, add a scrollbar, etc) in order to show everything in the modal page.
    I have written a function that does exactly that, but I have to execute the function after the page is loaded and the regions are shown. But, if I execute it using onload attribute, or setting a dynamic action which fires on page load, the function gets executed during the submit, before the regions are shown.
    I hope I have managed to clear up the problem.
    As always, thank you.

  • Execute Java code after login

    Hi experts,
    I'd like to execute some Java code after a successful login. I guess I could write a custom login module or use a WD Java iView to do this but a "better" solution may exist.
    Regards,
    Pierre

    Customizing your login module is probably your best bet. As soon as you're user is authenticated, you can execute your custom Java code.
    From my experience, I have not seen an easier / cleaner way to capture that event.
    Regards,
    Tom

  • Problems with 'background' JFrame focus when adding a modal JDialog

    Hi all,
    I'm trying to add a modal JDialog to my JFrame (to be used for data entry), although I'm having issues with the JFrame 'focus'. Basically, at the moment my program launches the JFrame and JDialog (on program load) fine. But then - if I switch to another program (say, my browser) and then I try switching back to my program, it only shows the JDialog and the main JFrame is nowhere to be seen.
    In many ways the functionality I'm looking for is that of Notepad: when you open the Find/Replace box (albeit it isn't modal), you can switch to another program, and then when you switch back to Notepad both the main frame and 'JDialog'-esque box is still showing.
    I've been trying to get this to work for a couple of hours but can't seem to. The closest I have got is to add a WindowFocusListener to my JDialog and I hide it via setVisible(false) once windowLostFocus() is fired (then my plan was to implement a similar functionality in my JFrame class - albeit with windowGainedFocus - to show the JDialog again, i.e. once the user switches back to the program). Unfortunately this doesn't seem to work; I can't seem to get any window or window focus listeners to actually fire any methods, in fact?
    I hope that kind of makes sense lol. In short I'm looking for Notepad CTRL+R esque functionality, albeit with a modal box. As for a 'short' code listing:
    Main.java
    // Not all of these required for the code excerpt of course.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    import javax.swing.plaf.basic.BasicSplitPaneUI;
    public class Main extends JFrame implements ActionListener, WindowFocusListener, WindowListener, FocusListener {
         static JFrame frame;
         private static int programWidth;
         private static int programHeight;
         private static int minimumProgramWidth = 700;
         private static int minimumProgramHeight = 550;
         public static SetupProject setupProjectDialog;
         public Main() {
              // Setup the overall GUI of the program
         private static void createSetupProjectDialog() {
              // Now open the 'Setup Your Project' dialog box
              // !!! Naturally this wouldn't auto-open on load if the user has already created a project
              setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );
              // Okay, for this we want it to be (say) 70% of the progamWidth/height, OR *slightly* (-25px) smaller than the minimum size of 700/550
              // Change (base on programWidth/Height) then setLocation
              int currProgramWidth = getProgramWidth();
              int currProgramHeight = getProgramHeight();
              int possibleWidth = (int) (currProgramWidth * 0.7);
              int possibleHeight = (int) (currProgramHeight * 0.7);
              // Set the size and location of the JDialog as needed
              if( (possibleWidth > (minimumProgramWidth-25)) && (possibleHeight > (minimumProgramHeight-25)) ) {
                   setupProjectDialog.setPreferredSize( new Dimension(possibleWidth,possibleHeight) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-(possibleWidth/2)), ((currProgramHeight/2)-(possibleHeight/2)) );
               else {
                   setupProjectDialog.setPreferredSize( new Dimension( (minimumProgramWidth-25), (minimumProgramHeight-25)) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-((minimumProgramWidth-25)/2)), ((currProgramHeight/2)-((minimumProgramHeight-25)/2)) );
              setupProjectDialog.setResizable(false);
              setupProjectDialog.toFront();
              setupProjectDialog.pack();
              setupProjectDialog.setVisible(true);
         public static void main ( String[] args ) {
              Main frame = new Main();
              frame.pack();
              frame.setVisible(true);
              createSetupProjectDialog();
            // None of these get fired when the Jframe is switched to. I also tried a ComponentListener, but had no joy there either.
         public void windowGainedFocus(WindowEvent e) {
              System.out.println("Gained");
              setupProjectDialog.setVisible(true);
         public void windowLostFocus(WindowEvent e) {
              System.out.println("GainedLost");
         public void windowOpened(WindowEvent e) {
              System.out.println("YAY1!");
         public void windowClosing(WindowEvent e) {
              System.out.println("YAY2!");
         public void windowClosed(WindowEvent e) {
              System.out.println("YAY3!");
         public void windowIconified(WindowEvent e) {
              System.out.println("YAY4!");
         public void windowDeiconified(WindowEvent e) {
              System.out.println("YAY5!");
         public void windowActivated(WindowEvent e) {
              System.out.println("YAY6!");
         public void windowDeactivated(WindowEvent e) {
              System.out.println("YAY7!");
         public void focusGained(FocusEvent e) {
              System.out.println("YAY8!");
         public void focusLost(FocusEvent e) {
              System.out.println("YAY9!");
    SetupProject.java
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class SetupProject extends JDialog implements ActionListener {
         public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              // Bad code. Is only temporary
              add( new JLabel("This is a test.") );
              // !!! TESTING
              addWindowFocusListener( new WindowFocusListener() {
                   public void windowGainedFocus(WindowEvent e) {
                        // Naturally this now doesn't get called after the setVisible(false) call below
                   public void windowLostFocus(WindowEvent e) {
                        System.out.println("Lost");
                        setVisible(false); // Doing this sort of thing since frame.someMethod() always fires a null pointer exception?!
    }Any help would be very much greatly appreciated.
    Thanks!
    Tristan

    Hi,
    Many thanks for the reply. Isn't that what I'm doing with the super() call though?
    As in, in Main.java I'm doing:
    setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );Then the constructor in SetupProject is:
    public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              And isn't the super call (since the class extends JDialog) essentially like doing new JDialog(frame,title,modal)?
    If not, that would make sense due to the null pointer exception errors I've been getting. Although I did think I'd done it right hence am confused as to the right way to handle this,if so.
    Thanks,
    Tristan
    Edited by: 802573 on 20-Oct-2010 08:27

  • Freezed modal jdialog in japplet

    I have made an applet program whose method javascript calls. And the method of the applet shows modal JDialog. But, after showing modal JDialog, the applet is locked.
    In Windows XP + JRE 6.2 + Firefox 2.0, it is locked just after showing modal JDialog.
    But in Windowx XP + JRE 5,4,3 + Firefox 2.0/IE, it is OK(working well) And, in Other OSes and Other browser, it is OK
    You can test this and watch java source in the below link.
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.html
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.java
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JOptionPane;
    public class FreezedJDialogInFFInJRE6InWindows extends JApplet {
         private Frame rootFrame;
         public void init() {
              rootFrame = JOptionPane.getFrameForComponent(this);
              showJDialog("it is called from init()");          
         public String showJDialogFromJS() {
              String msg = "it is called from showJDialogFromJS()";
              showJDialog(msg);
              return msg;          
         private void showJDialog(String msg) {
              JDialog dialog = new JDialog(rootFrame, msg, true);
              dialog.setSize(300, 300);
              dialog.setResizable(false);
              dialog.setVisible(true);
    {code}
    {code:javascript}
    <HTML>
    <HEAD>
         <SCRIPT language = "javascript">
              function install() {
                   var applet_tag = '<APPLET ID = "dialog_test"' +
                                       'CODE = "FreezedJDialogInIEInJRE5InWindows.class"' +
                                       'WIDTH = "0"' +
                                       'HEIGHT = "0">';
                   document.getElementById("applet_space").innerHTML = applet_tag;
              function showJDialog() {
                   if(!is_installed()) {
                        alert("not installed!");
                        return;
                   var returnValue;
                   try {
                        returnValue = document.dialog_test.showJDialogFromJS();
                   } catch (err) {
                        alert(err);
                   alert("return value is " + returnValue);
              function is_installed() {
                   if(document.dialog_test == null) {
                        return false;
                   } else {
                        return true;
         </SCRIPT>
    </HEAD>
    <BODY>
    <DIV id = "applet_space"></DIV>
    <SCRIPT>
         install();
    </SCRIPT>
    <INPUT TYPE="button" NAME="button" VALUE="showJDialog()" onClick=javascript:showJDialog()>
    </BODY>
    </HTML>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try placing it on the awt thread, for example:
    private void showJDialog(String msg) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                          JDialog dialog = new JDialog(rootFrame, msg, true);
                          dialog.setSize(300, 300);
                          dialog.setResizable(false);
                          dialog.setVisible(true);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there a way to display a  non modal JDialog on JApplet

    Whenever I try to add a non modal JDialog over a JApplet, the JDialog freezes and components on it never gets painted. After a disappointing search over web, I've kinda begin to hate swing. I am shocked that a very basic thing like this is so hard to achieve in Java. Any solution folks?
    My code is as follows:
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    public class DialogApplet extends JApplet {
         private javax.swing.JPanel jContentPane = null;
         private JButton jButton = null;
          * This method initializes jButton     
          * @return javax.swing.JButton     
         private JButton getJButton() {
              if (jButton == null) {
                   try {
                        jButton = new JButton();
                        jButton.setText("Click Me"); 
                        jButton.setBounds(75, 80, 147, 34); 
                        jButton.addActionListener(new java.awt.event.ActionListener() {
                             public void actionPerformed(java.awt.event.ActionEvent e) {   
                                  Frame f = javax.swing.JOptionPane.getFrameForComponent(jContentPane);
                                  JDialog pi = new JDialog(f, "MainFrame Dialog", false);
                                pi.getContentPane().add(new JLabel("I got to be working Bossie!!!"));
                                pi.pack();
                                pi.setLocation(75, 80);
                                pi.setVisible(true);
                                try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                                pi.setVisible(false);
                   catch (java.lang.Throwable e) {
                        e.printStackTrace();
              return jButton;
         public static void main(String[] args) {
          * This is the default constructor
         public DialogApplet() {
              super();
              init();
          * This method initializes this
          * @return void
         public void init() {
              this.setSize(300,200);
              this.setContentPane(getJContentPane());
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private javax.swing.JPanel getJContentPane() {
              if(jContentPane == null) {
                   jContentPane = new javax.swing.JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJButton(), null); 
              return jContentPane;
    }

    try this, it is really simple, just to look at
    example from the swing tutorials.
    Thanks my friend, If you carefully observe my code, I also needed some piece of code to run in the background ((The thread.sleep() part)) while displaying the dialog. The problem was the JDialog used to freeze and components on it never used to get painted. Finally I managed to find a way out. If we try to display a JDialog with a new thread, The event dispatching thread takes precedence and the painting of components on the JDialog happens only after even dispatching thread is done. All I did was display JDialog in the event dispatch thread and run the background process in new thread.
    My code.
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class DialogApplet extends JApplet {
        private javax.swing.JPanel jContentPane = null;
        private JButton jButton = null;
        private JDialog dialog = null;
         * This is the default constructor
        public DialogApplet() {
            super();
            init();
         * This method initializes this
        public void init() {
            this.setSize(300, 200);
            Container container = this.getContentPane();
            container.add(getJContentPane());
         * This method initializes jContentPane
         * @return javax.swing.JPanel
        private javax.swing.JPanel getJContentPane() {
            if (jContentPane == null) {
                jContentPane = new javax.swing.JPanel();
                jContentPane.setLayout(null);
                jContentPane.add(getJButton(), null);
            return jContentPane;
         * This method initializes jButton
         * @return javax.swing.JButton
        private JButton getJButton() {
            if (jButton == null) {
                try {
                    jButton = new JButton();
                    jButton.setText("Click Me");
                    jButton.setBounds(75, 80, 147, 34);
                    jButton.addActionListener(new java.awt.event.ActionListener() {
                            public void actionPerformed(java.awt.event.ActionEvent e) {
                                showDialog();
                } catch (java.lang.Throwable e) {
                    e.printStackTrace();
            return jButton;
         * This method displays Dialog
        public void showDialog() {
            final Frame frame = JOptionPane.getFrameForComponent(this);
            dialog = new JDialog(frame, "DialogApplet", false);
            dialog.setModal(true);
            Container contentPane = dialog.getContentPane();
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(new JLabel("I got to be working Bossie!!!"), BorderLayout.CENTER);
            contentPane.add(panel);
            dialog.pack();
            Thread t = new Thread() {
                    public void run() {
                        for (int i = 0; i < 100000; ++i) {
                            System.out.println(i);
                        dialog.hide();
            t.start();
            dialog.show();
    }

  • Non modal JDialog

    Hi All,
    I want a non modal JDialog which is used to show the message to the user that it is searching for the records, when a search is performed and records are retrieved from the database. When the search is going on user might hit cancel on the JDialog to cancel the search. My problem is, the cancel button on the Search dialog is not catching the event and user is not able to select the cancel option on the dialog.
    Here is my code :
    class SearchWindow extends JDialog {
    private JPanel btnPanel;
    private JLabel lblSearch;
    private JButton btnCancel;
    * Constructor
    public SearchWindow() {
    super((Frame)null, false);
    setTitle("Searching Shipment Legs");
    cancelled = false;
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent evt) {
    close();
    Container contentPane = getContentPane();
    contentPane.setLayout(null);
    addButtons();
    pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(new Dimension(300, 100));
    setSize(300,100);
    setLocation((screenSize.width-700)/2,(screenSize.height-450)/2);
    private void addButtons() {
    btnPanel = new JPanel();
    btnPanel.setLayout(new BorderLayout());
    lblSearch = new JLabel("Searching..........");
    btnCancel = new JButton("Cancel");
    btnPanel.setBackground(Color.lightGray);
    lblSearch.setBackground(Color.lightGray);
    btnCancel.setBackground(Color.lightGray);
    btnPanel.add(lblSearch, BorderLayout.CENTER);
    btnPanel.add(btnCancel, BorderLayout.SOUTH);
    btnCancel.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent evt) {
    System.out.println("cancel");
    cancelled = true;
    close();
    btnPanel.setBounds(0,0,200,50);
    this.getContentPane().add(btnPanel);
    lblSearch.setVisible(true);
    btnCancel.setVisible(true);
    this.getContentPane().validate();
    public void close() {
    this.setVisible(false);
    this.dispose();
    public void show() {
    super.show();
    paintComponents(getGraphics());
    this.setModal(false);
    Any help is greatly appreciated.
    Thanks,
    Bhaskar

    Hi Haroldsmith
    I am calling this search window in one of my programs where on button click it will fetch the records from the database. When this process is on, search dialog is shown up. Ths dialog is shown correctly and its getting closed as soon as the search is completed. But the probelm is its not allowing me to click on cancel button.
    Bhaskar

  • Stopping execution without modal Jdialog

    Hi there,
    I am writing a gui that needs to wait for a button click. I used to use a modal JDialog for this, which worked fine, but I have recently changed the GUI to a wizard style, and I would like to simply redraw a Card every time, rather than having a popup Dialog.
    Basically the program will show info, but this info will change whenever the button is pressed.
    How would I go about this without using a modal JDialog?, In other words, how can I make the program wait until button press? I am very confused about wait() and notify(), its not as simple as I thought, maybe someone can enlighten me.
    Thanks for any help

    Wow ok, I really screwed up on this one. Let me start again, For anyone still reading:
    The program I am writing presents the User with a choice to which they must reply with using a button press. This is easily done using a JDialog that is Modal as the program waits until the JDialog is disposed.
    My question is whether it is possible to achieve this effect without using a JDialog. I am doing it without a JDialog because I do not wish to have any pop ups, rather just a constantly refreshing JPanel.
    To sum up: How do I achieve the modal effect of a JDialog using other Components?
    I am unable to post any code right now, if anyone needs to see some I will gladly post it tommorow.
    Thanks again!

  • Problems of executive files after PC crash

    My developing PC was crushed last week when LabView project was programming. The culprit is due to device driver conflict from both Keithley USB driver and NI 488.2 driver. After recovered the corrupted project, the executive files started showing errors like"LabVIEW:Memory is full"; "LabVIEW Load error code 33: Could not load front panel data logging...";"LabVIEW:End of file encountered" ; "LabVIEW load error code 12: Could not load connector type map" etc... when executive files were distributed to run-time PC.
    I removed all LabView 8.0 developing suite and re-installed LabView 8.2. However, the problem was not resolved.  The executive files are ruuning no problems on developing PC but failed on run-time PC.
    I brought same source files to another developping PC and made executive files. They are also running fine on run-time PC. Really, I totally have no idea what's wrong with developping PC after crushed. How comes the installer and execution files start having problems even I re-installed LabVIEW? Thanks your kinding answer. 

    Some of those error codes have two possible causes. They are usually given as:
    Possible reason(s):
    LabVIEW:  Some system capacity necessary for operation is not enabled.
    =========================
    NI-488:  File system operation error.
    Since you had problems with the NI-488 driver, my guess is that the possible reason is the second listed . Uninstalling and installing LabVIEW does not automatically uninstall and re-install the hardware drivers. Try doing a repair of NI-488 or completely uninstall that and re-install.

Maybe you are looking for

  • I am trying to connect my MacBook Pro to my TV with a mini display port to HDMI converter. Its not working. Any suggestions?

    I am trying to connect my MacBook Pro to my TV with a mini display port to HDMI converter. Its not working. Any suggestions?

  • Custom Tag Capitalization Problem..

    All,           OS: Windows 2000           App Server: Weblogic 6.0 sp 2           JDK: 1.3 (and tried 1.3.1)           I have a set of custom tags that run fine when I use them on an app server (such as Enhydra) with JDK 1.2.2, but when I switch to J

  • Partner in inbound delivery

    Hi, I'm creating an inbound delivery with trx VL31N, I clicked on header button, then I clicked the Partner tab and if I click on Propose alternatives button the system prompts *There are no alternatives available for Vendor X*. I want the system pro

  • Ipod "Syncs" but doesn't add new music

    My ipod has always worked perfectly fine with my computer and itunes. Yesterday I added a new mixCD to my itunes and tried to sync it with my ipod. My ipod shows up in the sidebar, and goes through a "sync" process, but hasn't added the new music. Ad

  • Problem in Procedure!!!

    Hai, I am having a procedure XYZ. It will take the 7 tables count and it will display it using DBMS_OUTPUT. Table counts are taken using cursors C-C6. And then procedure XYZ is executed thro' a unix script. In that i spool the log file. The problem i