How to invoke OK button in Modal JDialog

Hi,
I have two buttons in a Modal JDialog box OK, Save. The functionalities are written in actionPerformed(). But when I click the OK or Save button, the function is not getting invoked.
JDialog jd = new JDialog();
jd.setModal(true);
jd.show;
Please give me a solution.
Thanks in Advance....

Actually, I didn't use Swing for some years now.
Hava a look at the API doc. Seems like you can pass a Component instead of a String for the message. Maybe you could use a ScrollPane or something like that.
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JOptionPane.html
What doc says about message arg:
A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type:
Object[]
An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.
Component
The Component is displayed in the dialog.
Icon
The Icon is wrapped in a JLabel and displayed in the dialog.
others
The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed.

Similar Messages

  • How to invoke the app by touching the screen (without using the home button)

    Kindly  provide the solutions for the following issues
    1.       How to invoke the app by touching the screen (without using the home button)
    2.       Estimated lifespan running an iPad3 continuously 24x7
    awaiting for your valuable response.
    Thanks and regards,
    Sathya.

    1.  You can only invoke an app by touching its icon.
    2.  All depends on what your app does.

  • Issues opening pdf in a modal jdialog

    Hi guys,
    I've a strange issue, I can't solve it.
    I'm newbie of java swing and this is a very difficult issue.
    I've a jdialog modal. In this jDialog I've a button, clicking on it a pdf is generated with itext.
    I observed that:
    -if I try to generate pdf from a frame, pdf is shown over the frame.
    -if I try to generate pdf from a jdialog swing(that's case I need) pdf is shown below jdialog...so I can't see pdf without closing jdialog and it's not good.
    How can I proceed in the second case?
    Thanks

    hi,
    thanks for your reply...I try to addo more detail.
    I have a modal jdialog.
    In it I have a button, clicking on it is called a method to create a pdf with itext.
    Here a snippet of code
    try {
                  Document document = new Document(PageSize.A4);
                   PdfWriter.getInstance(document, new FileOutputStream(FILE));
                   document.open();
                            create(document);
                   document.close();
                            String[] command = new String[3];
                   command [0] = "cmd.exe";
                   command [1] = "/C";
                   command [2] = "\"" + FILE+ "\"";
                            Runtime.getRuntime().exec(command );
              } catch (Exception e) {
                   e.printStackTrace();
                            JOptionPane.showMessageDialog(null, "Si è verificato il seguente errore: "+e.getMessage(), "Errore stampa pdf", JOptionPane.ERROR);
                            return;
              }Following this way pdf is opened but it's shown under the modal jdialog that called it.
    So for watching it I need to close modal jdialog.
    How can I run pdf to make it OVER a modal jdialog?
    Thanks,
    Regards

  • 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!

  • 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;

  • Modal JDialog needs disposing  TWICE!

    I have a simple JDialog that is modal over another JDialog. It has a cancel button whose action event simply calls dispose().
    However, on first invocation of cancel, the dispose() does not actually remove the dialog; it is only on a second click that dispose() actually does kill the dialog. I notice also that the first dispose() does not cause WindowClosed() to be called. I have verified that definitely only one instance of the dialog is being referenced (hashcode on each dispose is the same).
    The problem immediately goes away if I make the dialog non-modal, but I want it modal!!
    Any suggestions? Seems like a bug to me...(j2sdk1.4.1_01)

    By calling setVisible(false) the modal JDialog disappears and while it's invisible it's not modal (awt Dialogs do that, too). I was not able to reproduce your problem, but this piece of code may solve it:
    setVisible(false);
    dispose();

  • Change a modal JDialog to non-modal JDialog

    I created a modal JDialog initially, for some result i need change it to a non-modal JDialog, is there any set modal command can do it??

    Nope.
    The reason is because of program flow:
    System.out.println("first line");
    JDialog dialog = new JDialog(modal);
    dialog.setVisible(true); // blocks this flow if and only if modal is true
    System.out.println("second line");
    Try putting a button in the dialog which prints out "button pressed".
    If you press the button each time before closing the dialog you will get:
    when modal is true:
    first line
    button presed
    second line
    when modal is false:
    first line
    second line
    button prese

  • 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

  • How to set width for this modal dialog box?

    Hi All,
    How to set width to this modal dialog box:
    <input id="btnVote" onclick="javascript:SP.UI.ModalDialog.showModalDialog({ url: &#39;../Lists/Sports%20Activities%20Voting/NewForm.aspx&#39;, title: &#39;User Survey&#39;}); return false;" type="button" value="Vote"/>
    Thanks in advance!

    set as bellow:
    <input id="btnVote" onclick="javascript:SP.UI.ModalDialog.showModalDialog({ url: &#39;../Lists/Sports%20Activities%20Voting/NewForm.aspx&#39;, title: &#39;User Survey&#39;,width:700,height:350}); return false;" type="button" value="Vote"/>
    yaşamak bir eylemdir

  • Adobe Configurator - how to invoke action or script from html widget?

    How to invoke action or script from html wiget in Adobe Configurator?
    Please help! I tried to make it about 5 hours!
    I need something like that:
    I click link or image
    ...and it runs action.
    Thanks!

    If you click on the question mark ( as shown below) on the right of Configurator  2 window
    the user guide installed on your computer within Configurator 2  will open
    Anyway once you have your action or script button  in your panel you must select it and configure it in the  inspector palette

  • 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}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to invoke JSF With Standard Urls and parameters

    Hi,
    Could some one please help me how to invoke JSF with standard Urls and parameters?
    My requirement is:
    http://localhost:8080/myapp/faces/jsf_page.jsp?trackerID=11&viewPage="products"
    then i want to save the tracker details into database and redirect the user to "products" page.
    Would some one suggest me where can i get some example?

    Hi BalusC,
    It didn't solve my proble.....Your solutions are fantastic for most of the issues. But mine problem is unclear where JSF page tags.
    If possible, Could you please provide me how to invoke the method from JSF page....
    same code works if the user click on command button but my requirement is as soon as the user click on the link from 3rd party website, then he need to come to our web application and invoke the JSF page along with ManagedBean for saving details and redirect to disganted webpage.
    I will provide the following link to 3rd party websites. the URL is :: http://somedomain.com/myApp/Tracker.JSF?trackerID=111
    Could you please provide me the code i need to write in JSF ....just for invoking ManagedBean class...? how i code for page on load call the managedBean for specific method?

  • Can't start Thread from modal JDialog.

    Hi,
    this is a part of my code. I can't start the scanThread from the object WaitingDl. But if i close the modal JDialog (WaitingDl) the scanThread starts, please help:
    Thread scanThread = new Thread() {
    public void run() {                       
    // do something ....
    WaitingDl waitFrame = new WaitingDl("Waiting process", parent, scanThread, "Please wait ...");
    class WaitingDl extends JDialog {
    public WaitingDl(String title, JFrame parent, Thread thread, String waitingText) {  
    // a modal Dialog
    super(parent,true);
    // This command doesn't work!
    scanThread.start();
    Thanks!

    Hi,
    As suggestion :
    I think your JDialog is modal and visible by default, so
    when you invoke the contructor :
    WaitingDL d=new ......
    you enter to "modal state" so the Event thread is blocked and this append when you invoke super at
    contructor level.
    If you set your dialog not visible you can do :
    WaitingDL d=new .........
    // at this moment the contructor is invoked but the event thread is not blocked so your thread is started
    d.setVisible(true);
    // at this point the dialog is visible you enter at a modal state but your thread is running
    Hope this help
    Bye

  • Invoking Return button functionality internally

    We are calling a custom page from an existing page. We have added a link to the existing page and have set the Destination URI property to this new page URL. The functionality required on this custom page is that after the user enters the required values and clicks on OK button, the record should be inserted into the database and user should be redirected to the previous screen. The issue is that after we have inserted values into the database and we redirect to the previous screen using setForwardImmediately, it gives an error:
    You cannot complete this task because one of the following events caused a loss of page data:
    Your login session has expired.
    A system failure has occurred.
    I would like to know how to invoke Return functionality internally since it seems to be working fine. If anyone can also tell me why I am getting the above mentioned error, then it would be of great help.

    It would help if you outlined what technologies you are using here? Struts + JSP?, UIX?....

  • How to prevent (X button) closing window

    Hi!
    I am wondering how to prevent X button on
    the right top corner on the window closing
    the window.
    My jdev java app is intended to close window
    when user explicitly presses return button.
    That's works fine ... but how to catch
    window close event (X sys btn) and stop it?
    null

    Hi,
    You need to change the default close operation of JDialog or JFrame:
    myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

Maybe you are looking for

  • Zen Touch no longer uses fold

    At some point after an update (not sure if it was firmware or an update to MediaSource as I have applied both in the last 2 months) my 20GB Zen Touch stopped storing music in logical artist/album folders. Instead it stores all music files in the root

  • My iPhone is being hacked

    So, I've realised that my iPhone is being hacked, how is it possible that someone can hack into my iPhone and call and text people without having my phone with them? How do I stop this? Please help me find a solution to this, I love apple and if this

  • Charged for a returned phone.

    Before deciding to post this, I read many posts from other Verizon customers in similar situations. Before I go ahead and proceed further with an option on how to move forward, I am hoping to get more insight and advice from anyone willing to share t

  • Change production for SFC in a container

    Hi, During RMA receiving in SAP ME 6.0.4, we are doing Change production. If the SFC is packed into a container we get this error message "Change production not allowed for SFCs that are in a container" Then we have to unpack the SFC from the contain

  • How is this effect created of an HTML page peeling?

    I am familiar with the page Flip effect now quite popular to create flash-based virtual magazines but its the first time I see a page pull on an html page. Can anyone explain how its done please? http://www.anapharm.com/