Pass parent frame to Dialog, from panel within CardLayout

Hi!
I have a main class that uses card layout (EntryPoint.java), and where I instantiate all my panels from. All my panels(cards) are seperate classes.
I have a login class(card) that I call from my main class (LoginClass.java). When it displays and the user wants to change his/her password - I created a custom dialog to pop up and handle the request. This custom dialog is another class on it's own.
My problem is I cant seem to pass the frame to my dialog. I created a frame only in my main class, seeing the login panel is only a card displayed in my Main class.
I have followed the example at http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
Can anyone please assist me? I would greatly appreciate it. ;o)
Here is some code if it helps:
EntryPoint.java -----------------------------
public class EntryPoint extends JFrame {
    //instantiate the main frame
    public JFrame frame = new JFrame();
    //create a panel to add all of the components to
    private JPanel cards = new JPanel();   
    LoginClass lc = new LoginClass();
    public EntryPoint() {
        cards.add("login", lc);
        //add the panel to the frame
        frame.getContentPane().add(cards, BorderLayout.CENTER);
        frame.getContentPane().add(buttons, BorderLayout.PAGE_END);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
}LoginClass.java ----------------------------------
public class LoginClass extends JPanel  {
    private JButton loginB = new JButton("login"');
    CustomDialog customDialog;
    public boolean loginProceed = false;
    public LoginClass() {
        //this is where it shows in the example i have to pass parameters
//        customDialog = new CustomDialog(frame, "geisel", this);
//        customDialog.pack();
        this.setLayout(new GridLayout());
        this.add(loginBut);
        //set action listener to button ..................
    public boolean loginBut_actionPerformed(ActionEvent e) {
       //if password needs to be changed, invoke the dialog with this text
//                        customDialog.setLocationRelativeTo(frame);
//                        customDialog.setVisible(true);
//                        String s = customDialog.getValidatedText();
//                        if (s != null) {
//                            //The text is valid.
//                            setLabel("Congratulations!  "
//                                     + "You entered \""
//                                     + s
//                                     + "\".");
}My actual dialog is pretty much the same as
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/CustomDialog.java
Thanx for your help and time ;o)

Change the constructor for LoginClass and give it an argument:
public LoginClass(JFrame frame) {
    customDialog = new CustomDialog(frame, "geisel", this); // this line looks weird but without the code I cannot say for sure that it is wrong.
    customDialog.pack();
    this.setLayout(new GridLayout());
    this.add(loginBut);
}By the way.. if you are instantiating a JFrame in the main class, why does the main class also extend JFrame? Pick one pattern or the other and stick with it... I recommend that you NOT extend. So your JFrame oriented class should have a member JFrame and the JPanel oriented class should have a JPanel. This is not the way most people do it, but it is better design, even if only marginally so.
Drake

Similar Messages

  • Parent frame handling events from a child frame

    Hello, I'm making an app where i have a frame ("A" frame where A is a JFrame extended class) with a Button, nothing more nothing less, and, inside the mouseclick event I create an instance of another frame ("B" frame, created just by the common sentence B screenB = new B(); where B is a JFrame extended class) that it has, exactly like the parent, a Button but this has a different behavior, when i click the button of the "B" frame (Child) it's supposedly have to change the text of the button in "A" frame (Parent). In other words, an event in a child frame have to make changes in the parent frame, or the parent have to listen to events of the child to make any changes at the moment it happened, or whatever, what you understand the best for this.
    And another thing, in some apps you have a screen to fill some fields, and when you click a button or something, sometimes it appears another screen, let's say it has more fields, but that screen is now on the top of the screens and unless you close it or click a Ok button for say something, it denies you to do anything on the parent screen or another screen, like that are disabled or something. This is a property included in Frames, or it has to be imaginated and coded in java?
    Hope you can help me.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ListeningToChildren implements ActionListener {
        JLabel label;
        JFrame child;
        public void actionPerformed(ActionEvent e) {
            if(child == null)
                launchChild();
            else
                child.toFront();
        private void launchParent() {
            JButton button = new JButton("launch child");
            button.addActionListener(this);
            JPanel panel = new JPanel();
            panel.add(button);
            label = new JLabel("count = 0");
            label.setHorizontalAlignment(JLabel.CENTER);
            JFrame f = getFrame("Parent", new Point(200,200));
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(panel, "First");
            f.getContentPane().add(label);
            f.setVisible(true);
        private void launchChild() {
            JButton toParent = new JButton("talk to parent");
            toParent.addActionListener(listener);
            JButton openDialog = new JButton("open dialog");
            openDialog.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    String s = "<html><font color=blue size=8>" +
                               "Hello World</font></html>";
                    JLabel msg = new JLabel(s, JLabel.CENTER);
                    JOptionPane.showMessageDialog(child, msg, "modal dialog",
                                                  JOptionPane.PLAIN_MESSAGE);
            JPanel north = new JPanel();
            north.add(toParent);
            JPanel south = new JPanel();
            south.add(openDialog);
            child = getFrame("Child", new Point(450,200));
            child.addWindowListener(disposer);
            child.getContentPane().add(north, "First");
            child.getContentPane().add(south, "Last");
            child.setVisible(true);
        private JFrame getFrame(String title, Point loc) {
            JFrame f = new JFrame(title);
            f.setSize(200,150);
            f.setLocation(loc);
            return f;
        private ActionListener listener = new ActionListener() {
            int count = 0;
            public void actionPerformed(ActionEvent e) {
                label.setText("count = " + ++count);
        private WindowListener disposer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                child.dispose();
                child = null;
        public static void main(String[] args) {
            new ListeningToChildren().launchParent();
    }

  • Transfer Focus From a Child Dialog To its Parent Frame

    Hi
    I m working on a Multimedia Desktop Application. I have done alomst 90% of work. Here I have a problem to transfer focus from a Child Dialog to Parent Frame. Remember the whole applicatio does not use Mouse every thing is handled on key events. So I required to transefer the focus from a Child Dialog to its Parent Frame from key board. I also cant use ALT+TAB because
    1- Child is a dialog
    2- This is a Multimedia Application which will be deployed For TV production and can't allow any Computer
    Components to be viewable.
    So I want only key press to transfer the focus between Child and The Parent.
    Thanks.
    Khurram

    First u tell me what do u do on the forumI answer questions - when I know the answer.
    I give advice on how to use the forums efficiently so you get the best chance to have your question answered and you don't waste other peoples time.
    And the post-URL you mentioned, was mistakenly submitted two times.Then respond to your own thread saying you posted it twice by mistake.
    any ways I did never see any article posted by you, nor the solutions on the other's posts by you. you just made comments on others posts.which only goes to prove that you never bother to search the fourm before you post a question.
    and please let others try to review on my problem.others can still reply

  • How to make separate/individual text frame from one parent frame in indesign with javascript

    Hi all,
    Please suugest - how to make separate/individual text frame from one parent frame in indesign with javascript.
    Thanks
    Rohit

    @Larry – ah, your interpretation could be the right one…
    May I rephrase the question:
    "How to split threaded text frames to single ones?"
    "SplitStory.jsx" or "BreakFrame.jsx" under Scripts/Samples indeed could be the answer.
    From the comments in the code of "BreakFrame.jsx":
    //Removes the selected text frame (or text frames) from the
    //story containing the text frame and removes the text contained
    //by the text frame from the story.
    //If you want to split *all* of the text fames in the story, use the
    //SplitStory.jsx script.
    Uwe

  • Owb error(please pass a parent frame)

    Hi all,
    While synchronizing mapping in a process flow i am getting "this message is not modal pass a parent frame" error.My mapping has operating mode of "set based fail over to row based".Any idea why i am getting the error?

    Anyone??????????

  • How do I get a pop-up JDialog to return a result back to the parent frame?

    I have a button in a frame that opens up a JDialog with more buttons. Depending on the button pressed, the JDialog calculates an array and then closes the dialog. I'd like the results from the JDialog to be passed back to the parent frame. Is there any built in JDialog function allowing a passback upon closing to the parent frame or anything like that?
    If not, what's the best way to go about it?

    Is this a modal dialog? Then setVisible(true) blocks. The caller can retrieve the result after that call:
    dlg.setVisible(true);
    //now get result;

  • Passing parent reference

    This question is slighty related to another question of mine but is only theoretical:
    If a class can be instanciated from different parents. How does the child distinguish which parent is its?
    Would one set the parents reference in the child once it is created?
    Or can the child find out for itself which parent it belongs to?
    How would you that?
    Thank you for any suggestions.

    OK, that is clear.
    Mind you, after working my way through four +-1000 page books that claim to teach Java and which include the two Sun Java books I & II  I am overwhelmed with the notion that I was ripped off by these and wasted my time. That disappoints me most about the Sun 'novels'.
    One maybe an expert and not consider a JPane to be a child of a parent JPane, but the books are less strict. The principle of inheritance is systematically and consistently shown using JPanes in JFrames and other examplary hierarchical stuff. That a JPane within a JFrame has nothing to do with inheritance is a different matter.
    It is a Pavlov reaction that molds the learning brain into accepting that OO is the same as the demonstrated (suffocating) hierarchy.
    A 'component' in my 'uneducated world' can easily be part of an 'object'. (My car is built from thousands of components.) As 'components' are interwoven with the 'display concept' I consider both a component and a JPane to be objects, somehow hierarchaly related to one another.
    Only today I find myself to be given some clear answers on this forum (Swing). Asking my questions in the newbie section only gave me answers directing me to 'cardlayout', not answering my real questions (which in itself is not a problem, any answer pleases me - because I might be a fool unknowingly:).
    So if you would build any 'industrial' application and could change the name/address of a client in one part of the system or change the name/address of a supplier in another part of the system, you might like to know within the name/address -change-panel where 'you the child' would be offspring of as you might need to do something 'additional'. It might be bad code but not every mission to the moon was succesful either - and the need for it might spring from a 'maintenance request' after implementation (prohibiting redesign).
    Now honest to me I wouldn't know whether this is Swing or not. Interestingly, i just learned, I might get parent information if it is Swing (however the parent information may only refer to any "outer pane/frame/window" - haven't looked into that one yet- not a/the 'super' object).
    I understand that contrary to what the books tell me, the more practical code creates panels within panels (within panels etc) from one 'underlying' code base. Not the model the books teach: define/instanciate a class (fi JFrame) within one instanciates a new class (within ...) which happens to define a JPanel with an actionListener and a button to change some color. Handling events completely without refering 'outwards' within the class.
    With the first, more practical code, one needs to 'decouple the events' -the looser the better?
    Interestingly that looks a lot less like Java (as I 'know it') and lot more like the 'usual' win32 api or mac os x carbon 'event handling (put up some windows ... go wait (at one spot) and catch the incoming events - of course, for as far as I have read about these and comprehended it) and which gives me a stronger "I can handle that" feeling.
    Anyway, that was just all to clarify myself (and show disgust for my books).
    May I ask you what forum you would suggest me for these 'coupling' questions?
    And thank you for your clear answers, there is a lot of knowledge behind every one of them.

  • How to stop the Dialog from being dragged

    I was hoping that someone could tell me when calling a Dialog from Jframe, a how to stop the Dialog from being dragged
    while a dialog is showing.
    When it is visible I can still click and drag the Dialog
    I want to set it so you can not drag it until the dialog has be closed.

    If you don't have access to the parent frame, a "hack" that usually works:
    Frame frame = Frame.getFrames()[0];
    if (null != frame && frame instanceof JFrame){
    JFrame jf = (JFrame)frame;
    JDialog jd = new JDialog(jf, "title");
    ... code here ...
    As each JFrame (or Frame) is opened, its stored in the array of Frames that you can get. Same thing with Dialog.getDialogs(). Almost always, at least so far for me I've never had this problem, the [0] index is the main window opened, or the parent/top frame. I'd put the check in there to be safe and make sure its a JFrame and usually you'll only have the one JFrame.

  • Calling Dialog from a dialog- size constraints

    Hi,
    I am using Jdev version 11.1.1.7.1.
    I am calling a taskflow and running it as a dialog. I have a requirement to call another taskflow which runs as dialog from this dialog. When I do so, my child dialog is restricted within the parent dialog space. If the size of my child dialog is greater than my parent dialog, I get a scroll bar on the parent dialog, and have to scroll through it to view the child dialog completely.
    Is there a way I could avoid the scroll bar or render the child dialog outside the parent space ? What setting could be used?
    Thanks in advance,
    Punin

    You can only make the parent dialog biet to give the child more room.
    Timo

  • Need to get the parent frame

    I am popping up a dialog box from a JScrollPane made up of a JTable and some buttons. I do not know how to specify the Frame owner part of the constructor. How do I get the parent frame in for the JDialog constructor?
    Everything worked but then I realized my "dialog" was not a dialog box at all, just another frame... oops! This is an assignment so I have requirements I must adhere to. Now I am trying to convert it so it will truly be a Dialog box.
    I promise you I have read ALL of the trails and API and searched forums. Can anyone assist?

    try: SwingUtilities.windowForComponent( Component );
    and cast the result to a JFrame
    or try this link:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=189331
    which I found by search the Swing forum using the keywords - (parent frame)

  • Extended JDialog to pop-up in center of parent frame

    I have a JDialog extended, and I want it to pop up in the center of the parent frame when A button is pressed in the frame. The button is in the constructor of the main frame, and uses an anonymous inner class to attach the action listener to the button. I am calling the outter class (MainFrame) with the "this" reference, and I get bogus results. MapParameters is extended from JDialog.
    when I instantiate the JDialog with this line "mp = new MapParameters(MainFrame.this,true)" It puts the dialog in the upper left corner of the screen, which is the same results as if I were to use "null" where "MainFame.this" is.
    What am I doing wrong?

    You have to calculate the locations if you want to center the dialog on the frame. Add this code to either your the MainFrame where you create the dialog or in the JDialog extended class. Make sure the size of the dialog is set (ie it has been laid out if you are using a layout manager or set it using setSize if you are laying out components manually) before this code is executed.
    //Center the dialog
    Dimension frameSize = frame.getSize();
    Dimension dialogSize = dialog.getSize();
    if (dialogSize.height > frameSize.height) dialogSize.height = frameSize.height;
    if (dialogSize.width > frameSize.width) dialogSize.width = frameSize.width;
    dialog.setLocation((frameSize.width - dialogSize.width) / 2, (frameSize.height - dialogSize.height) / 2);

  • Looking for a way to pass parameter to external list from infopath

    Hey, i have a Sharepoint 2010 list for which I want to create Infopath form. I have an external content type and external list based on it.
    I want to prepopulate some fields in my Sharepoint list with data from external list. I tried to use external list as a secondary data source and query it for needed values. The issue I encounter is that my ECT has a finder with filter and I can't figure
    out how to pass a value to this filter within infopath.
    How can it be done with infopath? How can I pass the filter value to the external list using Infopath?

    Hi,
    According to your post, my understanding is that you wanted to pass parameter to external list from infopath.
    You need to query the external list from InfoPath using coding and CAML Query.
    Here is a similar thread for your reference:
    http://sharepoint.stackexchange.com/questions/33575/filtering-sharepoint-external-list-bcs-from-infopath
    Thanks,
    Linda Li
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Linda Li
    TechNet Community Support

  • "DEADLOCK" when showing dialog from RMI-callback.

    Hi!
    Today is the 10th day (full time) that I've been searching for a solution in Java Forums and Internet, but I couldn't find anything that helps me. Help is extremely appreciated, otherwise I'll go crazy! :-)
    The problem is that RMI-callback thread "somehow blocks" the Event Dispatch Thread.
    I want to do following:
    1) I push the button in the client (btDoSomething)
    (MOUSE_RELEASED,(39,14),button=1,modifiers=Button1,clickCount=1 is automatically pushed onto EventQueue)
    2) btDoSomethingActionPerformed is invoked
    3) inside of it I make a call to RMI-server (server.doSomething())
    4) from this server method I invoke RMI-callback back to the client (client.askUser())
    5) in the callback I want to display a question to the user (JOptionPane.showConfirmDialog)
    6) user should answers the question
    7) callback returns to server
    8) client call to the server returns
    9) btDoSomethingActionPerformed returns and everybody is happy :-)
    This works normally in normal Client, that means, while a button is pushed, you can show Dialogs, but with RMI callback I get problems.
    I just made a small client-server sample to simulate real project. What I want to achieve is that client invokes server method, server method does something, but if server method doesn't have enough information to make the decision it needs to do call back to the client and wait for input, so the user gets an JOptionPane.
    Here is my callback method:
        /** this is the remote callback method, which is invoked from the sevrer */
        public synchronized String askUser() throws java.rmi.RemoteException {
            System.out.println("askUser() thread group: " + Thread.currentThread().getThreadGroup());
            System.out.println("callback started...");
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        System.out.println("My event finished.");
            }catch (Exception e) {
                e.printStackTrace();
            try {
                Thread.currentThread().sleep(10000);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("callback finished.");
            return "Yo!"; // just return anything
        }Here in this sample I let the callback thread sleep for 10 seconds, but in real project I let it sleep infinitely and I want to wake it up after the user has answered JOptionPane. But I have the DEADLOCK, because event queue is waiting for callback to finish and doesn't schedule the "showing dialog" event which contains the command for waking up the callback thread.
    I looked very precisely when the event queue starts again to process events: it is precisely then when btDoSomethingActionPerformed is finished.
    When I'm not accessing GUI inside of the callback, this callback mechanism works perfectly, but as soon as I want to show the dialog from inside of the RMI-callback method, the "AWT Event Dispatch Queue" is somehow frozen until RMI-callback thread is finished (and in turn btDoSomethingActionPerformed terminates) . I cannot explain this weird behaviour!!!
    If I don't use SwingUtilities.invokeLater (I know this shoudn't be done outside of Event Dispatch Thread), but access the GUI directy, my JOptionPane is shown, but is not painted (it is blank gray) until callback thread returns.
    Why showing (or painting) of dialog is not done until btDoSomethingActionPerformed is finished?
    I also tried to spawn a new Thread inside of main RMI-callback thread, but nothing changed.
    I also tried the workaround from some older posting to use myInvokeLater:
        private final static ThreadGroup _applicationThreadGroup = Thread.currentThread().getThreadGroup();
        public void myInvokeLater(final Runnable code) {
            (new Thread(_applicationThreadGroup, new Runnable() {
                public void run() { SwingUtilities.invokeLater(code); }
            ).start();
        }but this didn't help either.
    Then I tried to spawn a new Thread directly from the Client's constructor, so that I'm sure that it belongs to the main appplication thread group. I even started that thread there in the constructor and made it wait for the callback. When callback came in, it would wake up that sleeping thread which should then show the dialog. But this did't help either.
    Now I think that it is IMPOSSIBLE to solve this problem this way.
    Spawning a new Process could work I think, but I'm not really sure if I want do to that.
    I know I could make a solution where server method is invoked and if some information is missing I can raise custom exception, provide the input on client side and call the same server mathod again with this additional data, but for that I need to change server RMI interfaces, etc... to fit in this concept. I thought callback would much easier, but after almost 10 days of trying the callback...I almost regreted it :-(
    Is anyone able to help?
    Thank you very much!
    Please scroll down for the complete sample (with build and run batch files), in case someone wants to try it. Or for the time being for your convenience you can download the whole sample from
    http://www.onlineloop.com/~tornado/download/rmi_callback_blocks_gui.zip
    ######### BEGIN CODE ####################################
    package callbackdialog;
    public interface ICallback extends java.rmi.Remote {
        public String askUser() throws java.rmi.RemoteException;
    package callbackdialog;
    public interface IServer extends java.rmi.Remote {
        public void doSomething() throws java.rmi.RemoteException;
    package callbackdialog;
    import java.rmi.Naming;
    public class Server {
        public Server() {
            try {
                IServer s = new ServerImpl();
                Naming.rebind("rmi://localhost:1099/ServerService", s);
            } catch (Exception e) {
                System.out.println("Trouble: " + e);
        public static void main(String args[]) {
            new Server();
    package callbackdialog;
    import java.rmi.Naming;
    public class ServerImpl extends java.rmi.server.UnicastRemoteObject implements IServer {
        // Implementations must have an explicit constructor
        // in order to declare the RemoteException exception
        public ServerImpl() throws java.rmi.RemoteException {
            super();
        public void doSomething() throws java.rmi.RemoteException {
            System.out.println("doSomething started...");
            try {
                // ask the client for the "missing" value via RMI callback
                ICallback client = (ICallback)Naming.lookup("rmi://localhost/ICallback");
                String clientValue = client.askUser();
                System.out.println("Got value from callback: " + clientValue);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("doSomething finished.");
    package callbackdialog;
    import java.rmi.server.RemoteStub;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.Naming;
    import javax.swing.JOptionPane;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    public class Client extends javax.swing.JFrame implements ICallback {
        private final JFrame parentFrame = this;
        private Registry mRegistry = null;
        private RemoteStub remoteStub = null;
        private IServer server = null;
        private final static ThreadGroup _applicationThreadGroup = Thread.currentThread().getThreadGroup();
        /** Creates new form Client */
        public Client() {
            initComponents();
            System.out.println("Client constructor thread group: " + Thread.currentThread().getThreadGroup());
            try {
                server = (IServer)Naming.lookup("rmi://localhost/ServerService");
                // register client to the registry, so the server can invoke callback on it
                mRegistry = LocateRegistry.getRegistry("localhost", 1099);
                remoteStub = (RemoteStub)UnicastRemoteObject.exportObject((ICallback)this);
                Registry mRegistry = LocateRegistry.getRegistry("localhost", 1099);
                mRegistry.bind("ICallback", remoteStub);
            }catch (java.rmi.AlreadyBoundException e) {
                try {
                    mRegistry.unbind("ICallback");
                    mRegistry.bind("ICallback", remoteStub);
                }catch (Exception ex) {
                    // ignore it
            }catch (Exception e) {
                e.printStackTrace();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
            secondTestPanel = new javax.swing.JPanel();
            btDoSomething = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.GridBagLayout());
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("RMI-Callback-GUI-problem sample");
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
            secondTestPanel.setLayout(new java.awt.GridBagLayout());
            btDoSomething.setText("show dialog");
            btDoSomething.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btDoSomethingActionPerformed(evt);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 3;
            gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
            secondTestPanel.add(btDoSomething, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 1.0;
            getContentPane().add(secondTestPanel, gridBagConstraints);
            pack();
        private void btDoSomethingActionPerformed(java.awt.event.ActionEvent evt) {                                             
            System.out.println(java.awt.EventQueue.getCurrentEvent().paramString());
            try {
                server.doSomething(); // invoke server RMI method, which will do the client RMI-Callback
                                      // in order to show the dialog
            }catch (Exception e) {
                e.printStackTrace();
        private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            try {
                mRegistry.unbind("ICallback");
            }catch (Exception e) {
                e.printStackTrace();
            setVisible(false);
            dispose();
            System.exit(0);
        /** this is the remote callback method, which is invoked from the sevrer */
        public synchronized String askUser() throws java.rmi.RemoteException {
            System.out.println("askUser() thread group: " + Thread.currentThread().getThreadGroup());
            System.out.println("callback started...");
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        System.out.println("My event finished.");
            }catch (Exception e) {
                e.printStackTrace();
            try {
                Thread.currentThread().sleep(10000);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("callback finished.");
            return "Yo!"; // just return anything
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Client client = new Client();
                    client.setSize(500,300);
                    client.setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton btDoSomething;
        private javax.swing.JPanel secondTestPanel;
        // End of variables declaration
    1_build.bat
    javac -cp . -d . *.java
    rmic callbackdialog.ServerImpl
    rmic callbackdialog.Client
    pause
    2_RunRmiRegistry.bat
    rmiregistry
    pause
    3_RunServer.bat
    rem java -classpath .\ Server
    java callbackdialog.Server
    pause
    4_RunClient.bat
    java callbackdialog.Client
    pause
    ######### END CODE ####################################

    I can understand that only partially, because SwingUtilities.invokeLater puts(redirects) my runnable object directly into AWT thread. The only conclusion I can draw from all things that I have tried until now , is that SwingUtilities.invokeLater(<showing the dialog>) invoked from a RMI thread somehow have lower "priority" than events coming directly from the AWT-thread and therefore it is held back until normal awt event completes (in this case BUTTON_RELEASED).
    But what I don't understand is the fact that the dialog is not shown even If I create and start a new thread from the client's constructor. This thread has nothing to do with RMI as it is in the main thread group:
        private BlockingObject dialogBlocker = new BlockingObject();
        private BlockingObject blocker = new BlockingObject();
        public Client() {
            initComponents();
            (new Thread() {
                public void run() {
                    try {
                        dialogBlocker.sleep(0);
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        blocker.wake();
                        System.out.println("My event finished.");
                    }catch (Exception e) {
                        e.printStackTrace();
            }).start();
            ...Callback is then only used to wake up this thread which should display the dialog:
        public Object askUser() throws java.rmi.RemoteException {
            System.out.println("callback started...");
            dialogBlocker.wake();
            blocker.sleep(0);
            System.out.println("callback finished.");
            return userChoice; // return anything I don't care for now
    class BlockingObject {
        public void sleep(long timeout) {
            synchronized(this){
                try {
                    wait(timeout);
                }catch (InterruptedException e) {}
        public void wake() {
            synchronized(this){
                notifyAll();
        }In this case the dialog is shown, but it is NOT painted, so I have deadlock again. Why it is not painted?!?
    Haven't I uncouple it from RMI-Thread?
    But perhaps I'm looking at the wrong side of the whole thing.
    If I invoke server.doSomething (as ejp proposed) in a separate thread, then everything is fine (except that I cannot use this solution in my project :-( ).
    It seems that the whole problem is NOT AT ALL related to callback itself, but rather to the fact that if client invokes remote call, even dialogs can't be shown until the rmi call returns to the client.
    Thank you, Drindilica

  • Call Dialog from another dialog

    hi everyone
    can anybody tell me how can we call one dialog from another dialog..
    Is it possible...???
    if it is, how we can we do ...please tell me with example
    thanks in advance

    Is it possible...???yes
    if it is, how we can we do ...please tell me with example
    public static void main(String[] args) {
       JDialog parent;
       for (int i = 0; i < 5; i++) {
          JDialog d = new JDialog(parent, true);
          parent = d;
          d.setVisible(true);
    }

  • Frame loading request from other frame

    Hai i have got a problem loading frames from one other frame.
    I have a framepage with in one frame an other frame page.
    From the main frame page i want to load some ordinary pages into the secundary framepage. I tried to do this with the following string:
    eval("parent.parent.secundaryframe.location='url'");
    When i do this i get an error message "parent.parent.secundaryframe is empty or not an object".
    What can be the cause of this.
    I have used the string several times before and it always worked perfectly.
    I hope someone can help me.
    Thanks.

    Hai Omer,
    I really appreciate the effort you put into answering my question. I learned some handy things from it.
    But i ment it a little less complicated.
    Say i have the following pages:
    main_frameset.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    load new pages into secundary frameset
    </body>
    </html>
    left.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    load new pages into secundary frameset
    </body>
    </html>
    secundary_frameset.html:
    ==================
    <html>
    <head>
    </head>
    <frameset rows="246,*" frameborder="YES" border="2" framespacing="2" cols="*" bordercolor="#FF0000">
    <frame name="topFrame" scrolling="NO" noresize src="top_secundary_frame.html" >
    <frame name="bottomFrame" src="bottom_secundary_frame.html">
    </frameset>
    <noframes><body>
    </body></noframes>
    </html>
    top_secundary_frame.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    some page loaded in this frame
    </body>
    </html>
    bottom_secundary_frame.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    some page loaded in this frame
    </body>
    </html>
    new_page1.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    A completly other page
    </body>
    </html>
    new_page2.html:
    ==================
    <html>
    <head>
    </head>
    <body>
    A completly other page
    </body>
    </html>
    Now, when i click on the link in left.html i want:
    new_page1.html to be loaded in the top frame of secundary_frameset.html
    new_page2.html to be loaded in the bottom frame of secundary_frameset.html
    This is what i exactly ment.
    Do you or anybody know how this is done?

Maybe you are looking for

  • X240 - SSD Cache M.2

    I ordered an X240 with a 16 GB SSD Cache drive.  Already, I am having a problem with it.  It is saying when I turn the machine on that there is a problem.  What I'd like to do is to just remove it and restore my HDD with an image I took.  However, wh

  • Can no longer change or Edit in Workgroup Manager

    I just moved and I was migrating my files to another computer and domain. No I can no longer authenticate to my workgroup manager to change anything. Here is what I did. Moved across the country Carbon Copied my 10.4 Server from my G5 tower to a G5 X

  • How to convert date from "yyyymmdd" to "MM/DD/YYYY" format

    1. I have one BLDAT field in my internal table.    its getting updated from input file. 2. The value in the input file is like yyyymmdd.    So the internal table field is filled like this    "YYYYMMDD". 3. After this,I have to compare this internal t

  • Oracle 9ir2 on Red Hat 8

    Hello all, I'm trying to install the Ora 9ir2 on RH 8 and have had some problems. I've did the dba group, user, run the root.sh changed the shmmax to a great value as manual. But in the final of installation the procecss was failed. In fact, on the t

  • Problem with Nested Templates, and Editable Attributes

    Hi all, I've run into the following problem. I have a template called A. I created a nested template B from A. I made an attribute editable to B, in A. The problem I am having is that I would like that attribute still editable in a page derived from