JOptionPane and JDialog

Hi guys,
I've been scooting around the net trying to find an answer to this problem. Basically I have a JDialog that users enter registration details. If they haven't completed all fields or if the password confirmation is wrong then a JOptionPane.showMessageDialog appears telling users what has happened. However if they were to then click ok in the OptionPane it closes both the option pane and the original Dialog window. Have you guys any idea?
A code snippet below:
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class Register extends JDialog implements ActionListener {
     //declare components
     JLabel lblHeading;
     JLabel lblUserName;
     JLabel lblUserPwd;
     JLabel lblCnfUserPwd;
     JLabel lblFrstName;
     JLabel lblLstName;
     JLabel lblAge;
     JLabel lblEmpId;
     JLabel lblSex;
     JLabel lblEmail;
     String usrName;
     String strUsrPwd;
     String strCnfPwd;
     String frstName;
     String lstName;
     String age;
     String empid;
     String email;
     String sex;
     Socket toServer;
     ObjectInputStream streamFromServer;
     PrintStream streamToServer;
     JComboBox listSex;
     JTextField txtUserName;
     JPasswordField txtUsrPwd;
     JPasswordField txtCnfUsrPwd;
     JTextField txtFrstName;
     JTextField txtLstName;
     JTextField txtAge;
     JTextField txtEmpId;
     JTextField txtEmail;
     Font f;
     Color r;
     JButton btnSubmit;
     JButton btnCancel;
     public Register() {
          this.setTitle("Registration Form");
        JPanel panel=new JPanel();
          //apply the layout
           panel.setLayout(new GridBagLayout());
           GridBagConstraints gbCons=new GridBagConstraints();
          //place the components
          gbCons.gridx=0;
          gbCons.gridy=0;
          lblHeading=new JLabel("Please register below");
           Font f = new Font("Monospaced" , Font.BOLD , 12);
          lblHeading.setFont(f);
          Color c=new Color(0,200,0);
          lblHeading.setForeground(new Color(131,25,38));
          lblHeading.setVerticalAlignment(SwingConstants.TOP);
          gbCons.anchor=GridBagConstraints.EAST;
          panel.add(lblHeading, gbCons);
          gbCons.gridx = 0;
          gbCons.gridy = 1;
          lblUserName = new JLabel("Enter Username");
          gbCons.anchor=GridBagConstraints.WEST;
          panel.add(lblUserName, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=1;
          txtUserName=new JTextField(15);
          panel.add(txtUserName, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=2;
          lblUserPwd=new JLabel("Enter Password ");
          panel.add(lblUserPwd, gbCons);
          gbCons.gridx = 1;
          gbCons.gridy = 2;
          txtUsrPwd = new JPasswordField(15);
          panel.add(txtUsrPwd, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=3;
          lblCnfUserPwd=new JLabel("Confirm Password ");
          panel.add(lblCnfUserPwd, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=3;
          txtCnfUsrPwd=new JPasswordField(15);
          panel.add(txtCnfUsrPwd, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=4;
          lblEmpId=new JLabel("Employee ID");
          panel.add(lblEmpId, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=4;
          txtEmpId=new JTextField(15);
          panel.add(txtEmpId, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=5;
          lblFrstName=new JLabel("First Name");
          panel.add(lblFrstName, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=5;
          txtFrstName=new JTextField(15);
          panel.add(txtFrstName, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=6;
          lblLstName=new JLabel("Last Name");
          panel.add(lblLstName, gbCons);
          gbCons.gridx = 1;
          gbCons.gridy = 6;
          txtLstName=new JTextField(15);
          panel.add(txtLstName, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=7;
          lblAge=new JLabel("Age");
          panel.add(lblAge, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=7;
          txtAge=new JTextField(3);
          panel.add(txtAge, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=8;
          lblEmail=new JLabel("Email address");
          panel.add(lblEmail, gbCons);
          gbCons.gridx=1;
          gbCons.gridy=8;
          txtEmail=new JTextField(20);
          panel.add(txtEmail, gbCons);
          gbCons.gridx=0;
          gbCons.gridy=9;
          lblSex=new JLabel("Sex");
          panel.add(lblSex, gbCons);
          gbCons.gridx = 1;
          gbCons.gridy=9;
          String [] sex= {"Male", "Female"};
          listSex = new JComboBox(sex);
          listSex.setSelectedIndex(0);
          panel.add(listSex, gbCons);
          JPanel btnPanel=new JPanel();
          btnSubmit=new JButton("Submit");
          btnPanel.add(btnSubmit);
          btnSubmit.addActionListener(this); //add listener to the Submit button
          btnCancel=new JButton("Cancel");
          btnPanel.add(btnCancel);
          btnCancel.addActionListener(this); //add listener to the Cancel button
          gbCons.gridx=0;
          gbCons.gridy=10;
          gbCons.anchor=GridBagConstraints.EAST;
          panel.add(btnPanel, gbCons);
          getContentPane().add(panel);
         setDefaultCloseOperation(DISPOSE_ON_CLOSE); //get rid of this window only on closing
          setVisible(true);
          setSize(450,400);
         }//end Register()
          public void actionPerformed(ActionEvent ae) {
               Object o = ae.getSource(); //get the source of the event
               if(o == btnCancel)
                    this.dispose();
               if(o == btnSubmit){
                    usrName = txtUserName.getText();
                    strUsrPwd = txtUsrPwd.getText();
                    strCnfPwd = txtCnfUsrPwd.getText();
                    frstName = txtFrstName.getText();
                    lstName = txtLstName.getText();
                    age = txtAge.getText();
                    empid = txtEmpId.getText();
                    email = txtEmail.getText();
                    sex = (String)listSex.getItemAt(0);
                    if ((usrName.length() == 0) || (strUsrPwd.length() == 0) ||
                    (strCnfPwd.length() == 0) || (frstName.length() == 0) ||
                    (lstName.length() == 0) || (age.length() == 0) ||
                    (empid.length() == 0) || (email.length() == 0))
                    JOptionPane.showMessageDialog(null,
                    "One or more entry is empty. Please fill out all entries.", "Message", JOptionPane.ERROR_MESSAGE);
                    if ((!strUsrPwd.equals(strCnfPwd))){
                         JOptionPane.showMessageDialog(null,
                         "Passwords do not match. Please try again", "Message", JOptionPane.ERROR_MESSAGE);
                    Thanks,
Chris

try something like this:
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class About extends JDialog {
/** Creates new form About */
public About(JFrame parent) {
super(parent,true);
initComponents();
pack();
Rectangle parentBounds = parent.getBounds();
Dimension size = getSize();
// Center in the parent
int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
setLocation(new Point(x, y));
and from the main dialog:
new About(this).setVisible(true);

Similar Messages

  • JOptionPane and JDialog.DO_NOTHING_ON_CLOSE broken?

    Hi there
    I've created a JDialog from a JOptionPane and I don't want the user to simply dispose of the dialog by clicking on the close button but they are still able and I'm sure that my code is correct. Is it my code that is wrong or is it a java bug? Oh I'm running on 1.3 BTW
    JFrame f = new JFrame();
    f.setSize(500, 500);
    f.setVisible(true);
    JOptionPane optionPane = new JOptionPane("Hello there", JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog d = optionPane.createDialog(f, "Testing");
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    d.setVisible(true);I know that I can just set up a JDialog directly and use the setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE) and it seems to work properly but I would like to see it work for JOptionPane!
    Thanks in advance

    Sorry but this doesn't make it work either. I've looked at the code for createDialog in JOptionPane and it actually adds a WindowListener to the dialog in there as well as a propertyListener. On closing the option pane it calls a method in windowClosing of the windowListener which in turn fires a property change event which then tells the dialog to dispose itself so the addition of another windowAdapter to override the windowClosing method will not help :-(
    I've managed to get round it by doing something similar to
    JFrame frame = new JFrame();
    final JDialog dialog = new JDialog(frame, "Testing", true);
    JButton button = new JButton("OK");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        dialog.dispose();
    JOptionPane optionPane = new JOptionPane(button, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    dialog.setContentPane(optionPane);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.pack();
    dialog.setVisible(true);

  • How to change the icon of JOptionPane and JFileChooser in swing

    Hi,
    Does any body know how to change the icon of JOptionPane and JFileChooser in swing.
    Please help me out in this.
    Thanx in advance.

    Try this
    import javax.swing.*;
    import java.awt.event.*;
    public class Untitled4 {
      public Untitled4() {
      public static void main(String[] args) {
        ImageIcon i = new ImageIcon("C:/TestTree/closed.gif");
        JOptionPane p = new JOptionPane();
        p.setMessage("This JOptionPane has my icon");
        p.setMessageType(JOptionPane.QUESTION_MESSAGE);
        p.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
        final JDialog d = p.createDialog("test");
        d.setIconImage(i.getImage());
        d.setVisible(true);
        d.setModal(true);
        if(Integer.parseInt(p.getValue().toString()) == JOptionPane.YES_OPTION) {
            System.out.println("You Clicked Yes");
    }

  • Help on assignment, don't understand JOptionPane and showInputDialog

    Hi, I am currently studying java and have problems doing my assignment. here is the assignment question. What I am looking for is pointers and hints to start on my assignment. I am not looking for the source code, rather the way to actually understand it and start writting my code
    I believe this assignment wanted me to create a class Object called Zeller with the methods in it and a ZellerTester to test the Object?
    I read up on the JOptionPane and the showInputDialog, but don't really quite understand it.
    Do i need a constructor for the Object Zeller?
    Does my assignment require me to put the showInputDialog as a method in the Zeller class? Or put it in the ZellerTester?
    The isLeapYear is a method in the Object Zeller?
    Here is the assignment question
    Examine the method
    showInputDialog() and study its function. Note the return type of this method.
    Write a program on the following requirements:
    1. Use the JOptionPane facility to ask the user for three positive integers,
    representing the day, month and year of a date.
    2. Use the Zeller�s congruence formula to find the day of the week.
    3. Should include a method boolean isLeapYear(int year)
    that will return true if year is a leap year, and false otherwise.
    The method should check for leap years as follow:
    return true if the year is divisible by 400.
    return true if the year is divisible by 4 but not by 100
    return false for the remaining values
    Thank you.

    I can't seems to return the method back to the main
    Not sure where has gone wrong...
    here is my code
    import javax.swing.*;
    public class ZellerTester
        public static void main(String[]args)
        int day  = 28;
        int month = 2;
        int year = 2007;
        int z;
        boolean isLeapYear;
        String[] displayName = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
        if(month==1 || month==2) {
            if (isLeapYear = false)
                day = day-1;
              else
                day = day-2;
        if(month<3)
            month = month + 12;
        z = (1 + day + (month * 2) + (3 * (month + 1) / 5) +
             year + year / 4 + year / 400 - year/ 100) % 7;
        System.out.println("The day is " +displayName[z]);
    public boolean isLeapYear(int year)
           if (year%400 == 0)
               return true;
           else if((year%4 == 0) && (year%100 != 0))
                return true;
           else
                 return false;
    }

  • JOptionPane and Threads

    I have a Class called Execute which runs as a thread. If this fails, then I want to show a JOptionPane from the main thread saying it failed (this works), but also I want to create a JOptionPane within the run() method of Execute stating the reason for the failure.
    I can not put a JOptionPane directly inside the run method 'cos it doesn't get rendered correctly, so I run this in it own thread. Only trouble is that now I have two modal dialog boxes appearing simultaneously; what I want is to have them appear consecutively. I have tried to join the thread that creates the pop-up but then it does not get rendered. Any ideas? I have posted an extract of the code below for testing
    public class Execute implements Runnable {
         File success = new File ("/ukirtdata/orac_data/deferred/.success");
         File failure = new File ("/ukirtdata/orac_data/deferred/.failure");
         success.delete();
         failure.delete();
         try {
             success.createNewFile();
             failure.createNewFile();
         catch (IOException ioe) {
             logger.error("Unable to create success/fail file", ioe);
             return;
         SpItem itemToExecute;
         if (!isDeferred) {
             itemToExecute = ProgramTree.selectedItem;
             logger.info("Executing observation from Program List");
         else {
             itemToExecute = DeferredProgramList.currentItem;
             logger.info("Executing observation from deferred list");
         SpItem inst = (SpItem) SpTreeMan.findInstrument(itemToExecute);
         if (inst == null) {
             logger.error("No instrument found");
             success.delete();
             return;
         String tname = QtTools.translate(itemToExecute, inst.type().getReadable());
         // Catch null sequence names - probably means translation
         // failed:
         if (tname == null) {
             //new ErrorBox ("Translation failed. Please report this!");
             logger.error("Translation failed. Please report this!");
             new PopUp ("Translation Error",
                     "An error occurred during translation",
                     JOptionPane.ERROR_MESSAGE).start();
             success.delete();
             return;
         else{
             logger.info("Trans OK");
             logger.debug("Translated file is "+tname);
                failure.delete()
                return;
        public class PopUp extends Thread implements Serializable{
         String _message;
         String _title;
            int    _errLevel;
         public PopUp (String title, String message, int errorLevel) {
             _message=message;
             _title = title;
             _errLevel=errorLevel;
         public void run() {
             JOptionPane.showMessageDialog(null,
                               _message,
                               _title,
                               _errLevel);

    Comeon,
    Someone must have some idea. I have tried making popup extend JOptionPane and implement Runnable, added a window listener which sets a boolean popDisplayed on windowOpen and windowClose, but this gets me nowhere (I have a Thread.sleep in the code as well)

  • JOptionPane and JList HELP!!!

    Hi there,
    I want to be able to use a JOptionPane and add these elements to my JList component. I know how to add elements to it through the source code but am not able to get a user to inout values into this JList. 've got my JOptionPane running by using the following code:
    public void actionPerformed(ActionEvent ae) {
           if(ae.getActionCommand().equals("New Player")){
                s1 = JOptionPane.showInputDialog("Enter player: ");
                list.append(s1);
           repaint();
      }I want the values taken from this Prompt and be shown in my JList. I tried doing:
    list.addElement(s1);
    list.append(s1);
    I tried looking at the Java API website but didn't find it helpful at all of what I'm trying to do.

    I keep getting an error on the line where it says:
    list.add(s1);And even when I try:
    list.addElement(s1);Still same error. Is it a different way of doing it?
    Thanks for any response

  • What is the difference between JFrame and JDialog?

    Is there any difference between JFrame and JDialog except that the JDialog can be modal?
    Is there any reason to use JFrame at all if i can achive the exactly the same with a JDialog?

    API wise they are basically the same, but they are usually built on top of different heavyweight components. Some platforms treat frames quite a bit differently than they do dialogs.

  • JOptionPane and UninitializedValue. Help

    I am trying to create a personalized dialog that has 2 buttons (OK and Cancel) and three RadioButton where the first two radio buttons disable input and when user presses OK it returns a fixed string and if the user chooses the third button input is enabled so he can enter his own input.
    Now everything seems fine except that when I run getInputValue it gives me "uninitializedValue" sometimes, sometimes it works and sometimes even though a new dialog comes in and I type something completelly new the old value is kept.
    I hope somebody can give me some tips.
    Code Snippet below (And sorry for the ugly code :P)
    public class JIDEDialog extends JOptionPane {
         public JIDEDialog()
         public String displayInputDialog(Component parentComponent,
    Object message,
    String title,
    int messageType,
    String projectName)
         final Object OK_OPTION = new Integer(1);
         final Object CANCEL_OPTION = new Integer(0);
    JButton aJButton = null;
    ButtonGroup group = new ButtonGroup();
    JRadioButton rButton = null;
    //JRadioButton r2Button = null;
    String defaultValue = null;
    Object[] options = null;
    if (title == null || title.compareTo("") == 0)
    title = "Type your input";
    //JOptionPane pane = new JOptionPane();
    setMessage(message);
    //pane.setOptionType(optionType);
    setMessageType(messageType);
    setIcon(null);
    options = new Object[5];
    aJButton = new JButton("OK");
    options[0] = aJButton;
    aJButton = new JButton("Cancel");
    options[1] = aJButton;
    rButton = new JRadioButton("Dat File");
    group.add(rButton);
    options[2] = rButton;
    rButton = new JRadioButton("Jar File");
    group.add(rButton);
    options[3] = rButton;
    rButton = new JRadioButton("Input");
    group.add(rButton);
    options[4] = rButton;
    group.setSelected(rButton.getModel(), true);
    setOptions(options);
    setWantsInput(true);
    setSelectionValues(null);
    setInitialSelectionValue(null);
    updateUI();
    final JDialog dialog = this.createDialog(parentComponent, title);
    dialog.setResizable(false);
    //setInitialValue(options[4]);
    selectInitialValue();
    ((JButton)options[0]).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
              setValue(OK_OPTION);
              //dialog.dispose();
              dialog.hide();
         ((JButton)options[1]).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
              setValue(CANCEL_OPTION);
              //dialog.dispose();
              dialog.hide();
         ((JRadioButton)options[2]).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
              setWantsInput(false);
         ((JRadioButton)options[3]).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
              setWantsInput(false);
         ((JRadioButton)options[4]).addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
              setWantsInput(true);
    dialog.show();
    //System.out.println(getInputValue());
    //If there is an array of option buttons:
    if(getValue() == OK_OPTION){
         if(((JRadioButton)options[2]).isSelected())
              defaultValue = ".."+System.getProperty("file.separator")+"data"+System.getProperty("file.separator")+projectName+".dat";           
         else if(((JRadioButton)options[3]).isSelected())
              defaultValue = ".."+System.getProperty("file.separator")+"data"+System.getProperty("file.separator")+projectName+".jar";
         else {
              defaultValue = (String)getInputValue();
    else {
              defaultValue = null;
    return defaultValue;
    Best Regards
    NooK

    Sorry for that, I did want some code tag when I posted the code at first but being new to this interface I couldn't find it and apparently I can't edit my own post above.
    As for uninitializedValue, there is not much more I could except that it is a constant in JOptionPane class
    static Object UNINITIALIZED_VALUE And also this info is given on the createDialog method but I didn't really get what they meant
    [bold]Each time the dialog is made visible, it will reset the option pane's value property to JOptionPane.UNINITIALIZED_VALUE to ensure the user's subsequent action closes the dialog properly.[bold]
    I have tried calling setInitialValue(Object) and selectInitialValue() to ensure that the initial value is not but I am not sure what initial value is meant (Like the button to be first selected when dialog is shown or the string to appear in the text field) so I couldn't do much but I suspect that some function is changing the initial valeu and I missed it.
    I paste the code again under tags
    public class JIDEDialog extends JOptionPane {
         public JIDEDialog() {}
         public String displayInputDialog(Component parentComponent,
                                                                                    Object message,
                                                                                    String title,
                                                                                    int messageType,
                                                                                    String projectName)
             final Object OK_OPTION = new Integer(1);
             final Object CANCEL_OPTION = new Integer(0);
                       JButton aJButton = null;
                       ButtonGroup group = new ButtonGroup();
                       JRadioButton rButton = null;
                      String defaultValue = null;
                      Object[] options = null;
                      if (title == null || title.compareTo("") == 0)
                      title = "Type your input";
                    setMessage(message);
                    setMessageType(messageType);
                    setIcon(null);
                    options = new Object[5];
                    aJButton = new JButton("OK");
                    options[0] = aJButton;
                    aJButton = new JButton("Cancel");
                   options[1] = aJButton;
                   rButton = new JRadioButton("Dat File");
                   group.add(rButton);
                   options[2] = rButton;
                   rButton = new JRadioButton("Jar File");
                   group.add(rButton);
                   options[3] = rButton;
                   rButton = new JRadioButton("Input");
                   group.add(rButton);
                   options[4] = rButton;
                   group.setSelected(rButton.getModel(), true);
                   setOptions(options);
                   setWantsInput(true);
                  setSelectionValues(null);
                  setInitialSelectionValue(null);
                  final JDialog dialog = this.createDialog(parentComponent, title);
                  dialog.setResizable(false);
                  selectInitialValue();
                   ((JButton)options[0]).addActionListener(new ActionListener()  {
              public void actionPerformed(ActionEvent ae)  {
                 setValue(OK_OPTION);
                  //dialog.dispose();
                 dialog.hide();
         ((JButton)options[1]).addActionListener(new ActionListener()  {
              public void actionPerformed(ActionEvent ae)  {
                 setValue(CANCEL_OPTION);
                  //dialog.dispose();
                 dialog.hide();
         ((JRadioButton)options[2]).addActionListener(new ActionListener()  {
              public void actionPerformed(ActionEvent ae)  {
                 setWantsInput(false);
         ((JRadioButton)options[3]).addActionListener(new ActionListener()  {
              public void actionPerformed(ActionEvent ae)  {
                 setWantsInput(false);
         ((JRadioButton)options[4]).addActionListener(new ActionListener()  {
              public void actionPerformed(ActionEvent ae)  {
                 setWantsInput(true);
            dialog.show();
            //If there is an array of option buttons:
            if(getValue() == OK_OPTION){
                 if(((JRadioButton)options[2]).isSelected())
                      defaultValue = ".."+System.getProperty("file.separator")+"data"+System.getProperty("file.separator")+projectName+".dat";                  
                 else if(((JRadioButton)options[3]).isSelected())
                      defaultValue = ".."+System.getProperty("file.separator")+"data"+System.getProperty("file.separator")+projectName+".jar";
                 else {
                      defaultValue = (String)getInputValue();
            else {
                 defaultValue = null;
            return defaultValue;
    }Hope this helps and hope someone can help me.

  • JOptionPane and Focus

    Hello All,
    I've got a small problem with setting the focus in a JOptionPane. My JOptionPane consists of one JComboBox and two JTextFields. I've created this JOptionPane by putting the components in an array and passing it to the JOptionPane constructor. Initially it starts with the focus on the top most component (the JComboBox). What i would like is to have it focussed on one of the JTextFields.
    Does anyone have any idea how to do this?
    Thanks in advance.

    Don't use a JOptionPane, why not use a modal JDialog? That way it is much easier to organise the components and arrange focus

  • Problem with refreshing JFrames and JDialogs

    My program is based on few JDialogs and one JFrame. I'm still changing them, one time one of the JDialogs is visible, other time JFrame. During this change I call dispose() for one window or frame and I create (if it wasn't created before) other component and call setVisible(true) for it. Problem is that sometimes (only sometimes! like 5% of calls) my windows appears but they are not refreshing (not showing new objects added to their lists or sth like that) until I resize my window by dragging mouse on the edge of it. Is there anyway to ensure that window will be displayed properly?

    I ran into this problem about a year ago...so I don't really remember but I think a call to validate(), or paint() or repaint() or something like that should do the trick (forgive me for not knowing the exact one but as I said it has been a while). Its been about that year since I stopped coding in java and moved to c#. You want the window to redraw its self what ever that is.

  • JOptionPane and JTables

    Hi guys, I hope everyone is fine.....
    Well, i try to finish a project and only have to solve two small problems, sorry for post two question here at the same time, but both are related with swing, so....
    1) I am using a JOptionPane.showMessageDialgo to show some error messages. Most part of the JOptionPane works properly, but there are someones which don't print the message and stop the entire system interface. I call
    JOptionPane.showMessageDialog(null, errorMsg, title, ERRORand only the tile is printed, the body of the Panel get a problem. I already try to put a fixed errorMsg and tile but the problem continues to happen - only the tile is printed and the Panel block all my interface.
    2) I am using JTable and create a special renderer to use buttons on my cells, as this buttons can reach distinct state I am using a collection of buttons to represent it. I am offer to use the functionality to clear the table, so I reset all the buttons but right here I got a problem. There are sometimes that my JTable call the Button renderer but don't call the getTableCellRendererComponent method to read the button. I think the table use some kind of buttfer, so, as the table don't call this method of my customized cell button the table use the last one, before clear the table.
    Someone can help me to fix this both cases!?!?! I don't post the code, because it is really big. But if anyone needs some small part, just ask me. Thanks all
    Giscard

    Hi guys, problem solved!!!!! :-)
    Just to register, the problem was:
    1) The thread which invoke the JOptionPane was a daemon thread, because it comes from RMI server. So this kind of thread - daemon - don't mount all gui components as I need. I am not sure, but I think if I wait for a long time the JOptionPane will be printed, because one day this thread should get the execution state.
    2)So, to solve I create a thread, set up it as not daemon setDaemon(false) and call the JOptionPane inside it. Note: If tou don't set the daemon the thread will get the configuration of the current thread, i.e. RMI execution thread that is daemon. So you need to set it by tour own.
    Right now, just left the table problem...:-)

  • JOptionPane and keystroke mappings

    Hi,
    The java doc for JOptionPane gives default keystroke mappings for JOptionPane as:
    "JOptionPane (Java L&F)
    Navigate in/out | Alt+F6
    Retract dialog | Esc
    Activate the default button (if defined) | Enter"
    I have a new class myOptionPane that overrides a number of the functions, and also the creation of the dialog used. Now I'm trying to catch this ESC, and in addition to the dialog retraction do something. Preferably, I could handle the ESC action myself. I tried overriding the processKeyEvent() function for the dialog, and tried adding a KeyListener to the dialog. Neither even caught the event! Its as if JOptionPane just eats up these events leaving no one an option to catch them!
    Any help?? Please!!!
    Shefali

    Hi,
    I created a class for the dialog I am using, and added the key listener in that, and then it works! For whatever reason, adding the key listener to the object wasn't working, I don't know why!!
    But thanks anyways,
    Shefali.

  • Problems with JOptionPane and intrrupting

    1.when i interrupt in main a thread,
    and the thread is executing a JOptionPane-Message,
    the interrupt is lost, if the thread is asking isInterrupted() bevor show Message, the Interrupt is visible. ITS A BUG?
    2. if a thread is creating a new JFrame() and obtains an interrupt, a error of JVM is reported:
    AWT blocker activation interrupted:
    java.lang.InterruptedException
    What can i do? please help me???

    Well what are you trying to interrupt, and why?
    I think the interrupt was meant to be used for when the application is shutting down. So those two problems of yours seem normal. Most other application wouldn't close while a dialog box was up, right?
    If you're trying to synchronize threads, look into the wait() and notify() methods in the Object class.

  • Can we add same JPanel twice??.. on JFrame and JDialog together!!

    Hello Frnds,
    my problem is quite weird!! i will try to explain..as much as I can !!
    My requirement is I want to show same JPanel in JDialog and JFrame at once..!!
    I am adding a
    JPanel A ---> JDialog
    JPanel A ---> JScrollPanel B
    JScrollPane B ---> JFrame.. and making frame and dialog visible together.. but JPanel is visible in dialog only..
    if i dont add in JDialog.. then JPanel is visible in frame.. !!.. but why that??
    JFrame fr = new JFrame();
    JPanel np = new JPanel();      // This JPanel is added Twice
    np.setBounds(0, 0, 128, 128);
    JScrollPane scroll=new JScrollPane(np);      // Once JPanel added here..
    scroll.setPreferredSize(new Dimension(385,385));
    fr.add(scroll);
    JDialog dlg=new JDialog(fr, "Another Panel", false);
    dlg.add(np);                        // Second Time JPanel added here..
    dlg.pack();
    dlg.setVisible(true);
    fr.setVisible(true);

    Let's make it very clear : it is NOT possible to add
    the same instance of a component to two different
    containers.
    Is it possible to have frame with component.. but on closing that frame component shifts to another frame.. and vice versa I will add to the above:
    it is NOT possible to add the same instance of a component to two different containers... at the same time. Does that clarify it?
    Why is it so hard to try it yourself?
    Instead of waiting a couple of hours hoping someone answers the question you could have solved your problem in a couple of minutes.

  • Advice needed about JFrame and JDialog (moved from java programming)

    My main class in my application is a page where the user can choose to register or login. This class is a JFrame. If the user chooses to register, my register dialog is called up and the parent JFrame passed to the dialog:
    private void btnRegister_actionPerformed()
                    new Register(this);
              }Same happens for login. If the user chooses to login, my login dialog comes up and my main class JFrame is set as its parent. This is all fine because all the calling up is done in my main class, so i can just use 'this' to pass the JFrame.
    Now here is my problem. If the user successfully logs in, they should have access to control some events. Now i am not sure if it will be ok to make this new events class another JFrame, as it is practically the start of a new section in my application.
    Thats my first question. My second question is if i do make this events class a JDialog, is it bad coding not to give it a parent frame? Or would this be acceptable? My worries is passing the main class JFrame to a class which is only accessable by going through two other classes.
    Cheers for the advice

    It's Simple dude,
    Advice: Use JIternalFrame, for your purpose.
    And if u want to go with JDialog than u can do that in main method. Like when u call JDialog
    Register dialog = new Register(this);Check for login in Register class or what ever u want. Create new method like success
    private boolean isSuccess() {
    return success;
    } at Register Class. After Registeration change the variable boolean success value to true or false as per logic
    And add
    Register dialog = new Register(this);
    if(dialog.isSuccess()) {
    // Show loginDialg(this) or else
    }Regards,

Maybe you are looking for

  • Why does permission not stay repaired?

    Every time I repair permissions Disk Utility reports the following: Group differs on "Library/Printers/InstalledPrinters.plist"; should be 80; group is 0. DU reports it as repaired every time, but then the next time it's the same thing. Why won't the

  • Show af:messages in info popup in 10g

    Hi, in 10g is there any fast way to display messages using af:messages in popup as in 11g. I red that if af:messages is missing the default operation in to open an info popup but the same is not happening in 10g. Thanks, Ilias

  • I can't print DL envelopes - help needed please

    Hi I have the 7500A office jet, all set up & running with office 2010 lovely printer but I just can not work out how to print DL sized envelopes, I can feed to envelopes into the printer select the size in say Word to DL but the printer will not prin

  • Error while trying to import using OdiImportObject

    When trying to import project using OdiImportObject from command prompt the following error is encountered... E:\ODIHome\oracledi\bin>startcmd.bat OdiImportObject -FILE_NAME=E:\slot\ego\patch\115\odi\US\mode\MFOL_PIM.xml -IMPORT_MODE=SYNONYM_INSERT_U

  • Still problems with "unknown server error"

    I followed the solutions in document (linked posted by Ken G Rice on 23/07/13) but am still getting "unknown server error" when attempting to sign in to Creative Cloud from my desktop. I'm using Mac OS 10.8.4. Would that cause a problem?