JOptionPane help

Using these instructions..
http://csc.colstate.edu/wright/cpsc1302/Projects/FMTuner/FMTuner.htm
Can someone please help me write the code for the JOptionPanes in the main method?
Here is my client code so far:
// FMTunerClient.java
import javax.swing.JOptionPane;
import java.util.ArrayList;
public class FMTunerClient
     public static void main(String[] args)
          String prompt = "Enter 1) A station frequency to tune to,\n2) \"List\" to see a list of available stations, or\n3)\"Quit\" to terminate the program.";
          String input = "";
          ArrayList<FMStation> stations = new ArrayList<FMStation> ();
          loadStations(stations); //
          FMTuner tuner = new FMTuner(stations);
          do
               try
                    input = JOptionPane.showInputDialog(tuner.toString() + "\n\n" + prompt);
                    // help with asking user questions
               catch(InvalidStationException e)
                    response = e.getMessage();
                    System.out.println("Invalid ");
          while(!input.equalsIgnoreCase("quit"));
     private String listStations(ArrayList<FMStation> stations)
          String temp = "Station List\n";
          FMStation currentStation = null;
          for(int i = 0; i < stations.size(); i++)
               currentStation = stations.get(i);
               temp += "\n" + currentStation.toString();
          return temp;
     private static void loadStations(ArrayList<FMStation> stations)
          stations.add(new FMStation("WJSP", 88.1, "Public Radio"));
          stations.add(new FMStation("WYFK", 89.5, "Religious"));
          stations.add(new FMStation("WFRC", 90.5, "Religious"));
          stations.add(new FMStation("WTJB", 91.7, "Public Radio"));
          stations.add(new FMStation("WIOL", 92.7, "Classic Rock"));
          stations.add(new FMStation("WVFJ", 93.3, "Christian Contemporary"));
          stations.add(new FMStation("WRLD", 95.3, "Oldies"));
          stations.add(new FMStation("WKZJ", 95.7, "Urban Contemporary"));
          stations.add(new FMStation("WTGZ", 95.9, "Alternative"));
          stations.add(new FMStation("WMXA", 96.7, "Top-40"));
          stations.add(new FMStation("WCRU", 97.1, "Religious"));
          stations.add(new FMStation("WRVX", 97.9, "Adult Contemporary"));
          stations.add(new FMStation("WMGP", 98.1, "Hot AC"));
          stations.add(new FMStation("WAGH", 98.3, "Urban Contemporary"));
          stations.add(new FMStation("WKCN", 99.3, "Country"));
          stations.add(new FMStation("WGSY", 100.1, "Adult Contemporary"));
          stations.add(new FMStation("WEAM", 100.7, "Gospel Music"));
          stations.add(new FMStation("WCJM", 100.9, "Country"));
          stations.add(new FMStation("WTGA", 101.1, "Adult Contemporary"));
          stations.add(new FMStation("WBFA", 101.3, "Hip Hop"));
          stations.add(new FMStation("WELR", 102.3, "Country"));
          stations.add(new FMStation("WCKS", 102.7, "Hot AC"));
          stations.add(new FMStation("WVRK", 102.9, "Rock"));
          stations.add(new FMStation("WFXE", 104.9, "Urban Contemporary"));
          stations.add(new FMStation("WSTH", 106.1, "Country"));
          stations.add(new FMStation("WCGQ", 107.3, "Hot AC"));
}

[url http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html]How to Use Option Panes

Similar Messages

  • JOptionPane help please - I'd be v. grateful

    Hi,
    Can you help me please? I'm just learning Java and was curious if it's possible to change the font color of text in a MessageDialog?
    For example, if I was saying something like
    JoptionPane.showMessageDialog(null,
    "\n I have 2 cats" +
    "\n I have 1 dog" +
    "\n I have 3 budgerigars" +
    "\n" +
    "\n I have " + numberOfPets + " pets", JOptionPane.INFORMATION_MESSAGE)How do I change the last line for example to be in red and perhaps bold?
    Also for the lines above the last line, I wanted to indent these but if I try "\t" after the "\n", it does not work.
    Can somebody help me please?
    Many thanks
    Edited by: steveb on Nov 6, 2007 10:50 AM

    If you are new to Java, you shouldn't be worrying about little tweaks like this -- concentrate on learning object-oriented concepts.
    Anyway, the message string can include some html markup:
    String msg = "<html>foo <i>bar</i> <font color='green'>baz</font></html>";
    JOptionPane.showMessageDialog(null,msg);

  • JOptionPane Help Needed

    I basically have two problems with JOptionPane that I've searched for answers yet I haven't found an applicable answer for my application. Here they are:
    1) How can I get a JPasswordField in a JOptionPane to be given focus when the JOptionPane is displayed?
    2) How can I get the default key mappings for JOptionPane not to work or atleast make it where when a user hits "Enter", it activates the button that has current focus? I have a problem with highlighting "Cancel" and hitting "Enter".
    Here is my code being used for the JOptionPane:
    String pwd = "";
    int tries = 0;
    JPasswordField txt = new JPasswordField(10);
    JLabel lbl = new JLabel("Enter Password :");
    JLabel lbl1 = new JLabel("Invalid Password.  Please try again:");
    JPanel pan = new JPanel(new GridLayout(2,1));
    int retval;
    while(tries < 3 && !valid)
         if(tries > 0)
              pan.remove(lbl);
              pan.remove(txt);
              pan.add(lbl1);
              pan.add(txt);
              txt.setText("");
         else
              pan.add(lbl);
              pan.add(txt);
         retval = JOptionPane.showOptionDialog(DBPirate.appWindow,pan,
         "Password Input",                              JOptionPane.OK_CANCEL_OPTION,                              JOptionPane.QUESTION_MESSAGE,
         null,null,null);
         if(retval == JOptionPane.OK_OPTION)
              pwd = new String(txt.getPassword());
              setPassword(pwd);
              if(cryptoUtil.testPassword(pwd))
                   valid = true;
              else
                   tries += 1;
         else
              System.exit(0);
    }Any help would be appreciated. Thanks, Jeremy

    Hello Jeremy,
    I am not too happy with my code, for I think there must be something more efficient and elegant. But after trying in vain with KeyListener and ActionMap this is presently the only way I could do it.
    // JOptionPane where the <ret>-key functions just as the space bar, meaning the
    // button having focus is fired.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ReturnSpace extends JFrame implements ActionListener
    { JButton bYes, bNo, bCancel;
      JDialog d;
      JOptionPane p;
      public ReturnSpace()
      { setSize(300,300);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container cp= getContentPane();
        cp.setLayout(new FlowLayout());
        JButton b= new JButton("Show OptionPane");
        b.addActionListener(this);
        p=new JOptionPane("This is the question",
              JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
        d=p.createDialog(this,"JOptionPane with changing default button.");
        FocusListener fl= new FocusAdapter()
        { public void focusGained(FocusEvent e)
          {     JButton focusButton= (JButton)(e.getSource());
         d.getRootPane().setDefaultButton(focusButton);
        int i=1;
    //    if (plaf.equals("Motif")) i=2;
        bYes = (JButton)((JPanel)p.getComponent(i)).getComponent(0);
        bYes.addFocusListener(fl);
        bNo = (JButton)((JPanel)p.getComponent(i)).getComponent(1);
        bNo.addFocusListener(fl);
        bCancel = (JButton)((JPanel)p.getComponent(i)).getComponent(2);
        bCancel.addFocusListener(fl);
        cp.add(b);
        setVisible(true);
        d.setLocationRelativeTo(this);
      public void actionPerformed(ActionEvent e)
      { bYes.requestFocus();
        d.setVisible(true);
        Object value = p.getValue();
        if (value == null || !(value instanceof Integer))
        { System.out.println("Closed");
        else
        { int i = ((Integer)value).intValue();
          if (i == JOptionPane.NO_OPTION)
          { System.out.println("No");
          else if (i == JOptionPane.YES_OPTION)
          { System.out.println("Yes");
          else if (i == JOptionPane.CANCEL_OPTION)
          { System.out.println("Cancelled");
      public static void main(String argsv[])
      { new ReturnSpace();
    }Greetings
    Joerg

  • InputVerifier and JOptionPane help please

    I am trying to create an application and require to validate input fields. I have successfully written the code to use the InputVerifier class to validate the input but want to use a JOptionPane dialog to notify errors. This doesn't seem to work as the JOption Pane is treated as an attempt to shift focus from the field being validated (which calls shouldYieldFocus() which tries to show a JOptionPane which tries to shift focus .........). I have a temporary fix by using an disabled text field to display the message but it isn't very elegant. Anyone any ideas please ?

    Did you get any solution?
    I am also facing the same problem but with Jdk 1.4 only.
    In Jdk 1.3 it's working fine.
    Please let me know if u have any solution

  • Help with JOptionPane.showInputDialog

    Hi!!
    People here helped me before so trying my luck again:)
    In order to get information from people I use JOptionPane.showInputdialog,
    problem is if I need to get 2 different types of info I have to use
            naam = JOptionPane.showInputDialog(null, "Geef speler naam:");
            land = JOptionPane.showInputDialog(null, "Geef Land Speler:");Is there anyway to make this happen in 1 screen?
    Or do I have to make a new frame for that with textfields and such?
    if so, anyone got an example?

    im new here:) so.. New to Java Technology suits me
    well I guess.No it doesn't. New to Java forum is for classpath questions, simple compile time problems and lazy students to cross post their assigments into.
    Swing questions, such as the one you asked, should be asked in the Swing forum because the people who answer questions in there are more knowledgeable about Swing. Plus you will almost 100% likely to find working example codes from previous posts in the Swing forum for Swing related questions.
    Much more likely than in here anyway.

  • Cannot Import javax.swing.JOptionPane   Please HELP!!!

    import javax.swing.JOptionPane;
    this line of code returns the error:
    C:\Java Files\BankAccount\BankAccount_Test.java:1: Class javax.swing.JOptionPane not found in import.
    import javax.swing.JOptionPane;
    ^
    1 error
    Process completed.
    Please help, I don't know what the problem could be....

    Swing was not part of any JDK's earlier than 1.2. Swing (or anything with a J in front of it, ie. JFrame, JOptionPane, etc...) was probably the most dramatic (if not largest) modification/addition to the Java language, that's why versions later than, and including, 1.2 are known as "Java 2".

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

  • Needing help organizing JOptionPane outputs

    Evening all,
    I'm trying to have a few variables whose info I get from JOptionPane such as Id, Name, Address etc.. to print out in a finished JOptionPane. The program I have so far prints it out nice and neat in the cmd window, but I havent had to make it printout in a JOptionPane window all nice and neat.
    Would anyone be able to supply a small portion of code for this?
    I would need it to print out like so
    (title of the window is College of Java)
    Id:
    Name
    Address
    Major
    Status
    Gpa
    Many Thanks to all who help :)

    String message = "Id:\nName\nAddress\nMajor...";
    JOptionPane op = new JOptionPane();
    op.showMessageDialog(this, message, "High Scores", JOptionPane.PLAIN_MESSAGE);Like that?

  • Help Button in JOptionPane

    Hi all,
    is there any easy way to provide a (possible locale sensitive) Help Button in JOptionPane Dialogs? Are there any libs that extend the Standard Dialogs to provide such a button?
    Many thanks for your ideas!
    bye
    Marcus

    This guy made his own alternative OptionPane that has such a feature:
    [http://javagraphics.blogspot.com/2008/06/joptionpane-making-alternative.html|http://javagraphics.blogspot.com/2008/06/joptionpane-making-alternative.html]

  • JOptionPane goes behind browser window (Help PLEASE!)

    I apologize if this is not the best place to post this question.
    I have an applet that open a JOptionPane using the following:
    int rc = JOptionPane.showConfirmDialog(null,
    "Do you want to save the changes you made to " + appInfo.getName() + "?", ProductInfo.ProductName,
    JOptionPane.YES_NO_CANCEL_OPTION,
    JOptionPane.WARNING_MESSAGE);
    THE PROBLEM I'm seeing is that this JOptionPane pops up for a second and then goes behind the applet browser window.
    I have 2 html files (index.html and product.html). index.html opens product.html in a new browser window (minus the toolbar and menu) using a small javascript (see below for code).
    I only see this problem when I open product.html via index.html. When I open product.html by itself this problem does not occur.
    Please help if you can - thanks ahead of time!!
    INDEX.HTML
    ===============================
    <html>
    <head><title>ProductName&trade;, Version 2.0</title></head>
    <body>
    <script>
    <!--
    /*Full screen window opener script: Written by JavaScript Kit (www.javascriptkit.com) More free scripts here*/
    function winopen(){
    var targeturl="./product.html"
    newwin=window.open("","","scrollbars")
    if (document.all){
    newwin.moveTo(0,0)
    newwin.resizeTo(screen.width,screen.height)
    newwin.location=targeturl
    //-->
    </script>
    <script>winopen()</script>
    </body>
    </html>

    Solved my own problem!!
    I modified index.html (see below) and it now works - the JOptionPane stays on top. Still don't know why though.
    INDEX.HTML
    =============================
    <html>
    <head><title>SwitchView&trade;, Version 2.0</title>
    <SCRIPT>
    function fullWindow(url) {
    var str = "left=0,screenX=0,top=0,screenY=0,resizable";
    if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    str += ",height=" + ah;
    str += ",innerHeight=" + ah;
    str += ",width=" + aw;
    str += ",innerWidth=" + aw;
    win=window.open(url, "w", str);
    </SCRIPT>
    </head>
    <body>
    <script>fullWindow('./product.html')</script>
    </body>
    </html>

  • Help!JOptionPane

    Hello,
    I'm currenntly facing some problems with my application.
    I have developed a passwordframe for an application and what i like to do is after the user keys in 3 trys of the password the frame would actaully dispose.
    But currently i'm having a probelm displaying the error message.
    I relly hope that you guys can help me cause my project is due really soon!
    my codes for the above as as below.
         b1.addActionListener (
         new ActionListener() {
              public void actionPerformed(ActionEvent e)
              String str1 = new String(tf1.getText());
                   String str2 = new String(password.getText());
                   do
                   if (str1.equals("staff") && str2.equals("abc123"))               
              theFrame something = new theFrame();
                   something.show();
                   else{
                   JOptionPane.showMessageDialog(
                   null,"Wrong PASSWORD! You only have 3 tries",
                   JOptionPane.ERROR_MESSAGE);
                   while (tries <= 3);
    i have an error and a warning the error is wrong number of arguments in a method related to the JOptionPane and the warning is password frame overrides a depreaciated API. I really hope that u guys can help me with this erroe
    Thanks!
    -palv-

    Hello,
    Thanks for your help thus far you help is GREATLY appreaciated but i'm having warning msg for example
    PasswordFrame.java uses or overrites the depreacated API. I'm having a probelm where by after the Password screen when i go to the next screen the itemlistener does not work..
    has that msg go to do anything with the item listener because when i complie it as a frame alone without going through the passwordframe it works....
    Once again
    thanks
    pal

  • JOptionPane.showMessageDialog(Component, Object) Help

    Hi,
    I am trying to use the JOptionPane, to display a MessageDialog.
    But, the message should be displayed with special font(BOLD), and the message should have background color(Red). The message is too long, so, I had to set location, with the following code, the dialog window is displayed but I am not able to see the text message. It appears as one red line. Could someone help me in fixing this.
    Not sure, if I have to use Layout, would BoxLayout fix the problem?
    The code is:
    com.sun.java.swing.JPanel displayPanel = new com.sun.java.swing.JPanel();
    com.sun.java.swing.JLabel displayLabel1 = new com.sun.java.swing.JLabel();
    com.sun.java.swing.JLabel displayLabel2 = new com.sun.java.swing.JLabel();
    displayLabel1.setText(getReactivationMessage().substring(0,23));
    displayLabel1.setFont(new java.awt.Font("dialog", 1, 15));
    displayLabel2.setText(getReactivationMessage().substring(23));
    displayLabel2.setFont(new java.awt.Font("dialog", 1, 15));
    displayPanel.setLayout(null);
    displayLabel1.setSize(30, 20);
    displayLabel2.setSize(100, 20);
    displayLabel1.setLocation((displayPanel.getWidth()-30)/2,(displayPanel.getHeight())/2);
    displayLabel2.setLocation((displayPanel.getWidth()-100)/2,(displayPanel.getHeight()-20)/2);
    displayPanel.add(displayLabel1);
    displayPanel.add(displayLabel2);
    displayPanel.setBackground(java.awt.Color.red);
    com.onstar.businessApplications.swing.uiComponentLibrary.widgets.JOptionPane_On.showMessageDialog(winMgr.getCCSAgentWindow(),displayPanel);
    Thanks in Advance

    I didn't quite understand the problem, but if the problem is that the text runs all along one line, and therefore runs out of the right hand side of the dialog window, this is because you need to use a wrapping label.
    JLabel does not wrap text. There is a way to allow for this. This is by putting your string within an open and close html tag (i.e. <html>***myTextHere***</html>).
    Another option would be for you to extend JLabel and write a JWrapLabel or somesuch.
    HTH,
    Manuel Amago.

  • Help with JOptionPane -- Popup Dialog Boxes

    I need to create a popup dialog box that looks like this:
    http://img88.imageshack.us/img88/6900/jbuttonpm2.jpg
    red = JTextField (Where the user will input a number that I need to store)
    green = Drop Down List with 1,2,3 as choices
    blue = JButtons for OK and Cancel
    So yeah, I need an easy way to collect a bunch of information from the user, and this was the best way I could think to do it. The user has to enter a number for all of the fields, but is there any way for the field to have a value of 0 there by default?
    I read some of the Java tutorials for using the JOptionPane's showXXXDialog but I wasn't sure if that can't of method could create such a complex dialog box. Any help would be really appreciated. How can I make that dialog box and get all the input I need from it?

    Create a panel containing red and green and pass it as message to JoptionPane.showConfirmDialog with OK_CANCEL_OPTIONS to have blue. If it returns OK_OPTION read and use values from panel. That's it.

  • 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

  • JOptionPane glitches - need help!

    Hi,
    I am building a java application that is full-screen. It is not set to always be on top. What happens is that the user is supposed to drag one of the green shapes onto the board. If they drag the shape and let go slowly, the JOptionPane shows up correctly. If they drag the shape and let go fast while they are dragging it, it causes problems with the display of the JOptionPane dialog. Below are some screen-shots of the problem:
    [http://www.thedigitallion.com/temp/ex1.jpg]
    [http://www.thedigitallion.com/temp/ex2.jpg]
    The JOptionPane shows up on mouse button release because that is how I test for when they stop dragging it. It seems like it still animates the shape after the joptionpane comes up and that is why it doesn't refresh the screen afterward. Here is a code snippet:
    [http://www.thedigitallion.com/temp/code.txt]
    Any help would be greatly appreciated!!!
    Ryan

    Point A
    JOptionPane.showInputDialog(....);
    Point BA modal dialog serves two purposes. One is that it dosen't allow you to get to Point B until the dialog is closed. You are using this property in your code to get input and then handle the input only after the dialog is closed. The second purpose of a modal dialog is to cut off functionality to the parent frame. If I try to click on the parent frame then Windows will make a "beep" sound and the dialog's window decorations will flash. I have to handle the dialog before I can start working with the frame again.
    This would seemingly pose a problem though if the modal dialog is shown on the EDT (short for Event Dispatch Thread). The EDT is the thread that handle's all your GUI events (painting, key input, mouse input, focus changes, component resizes ... bascially anything and everything that extends java.awt.AWTEvent ). It's a simple matter of fact that if you hold up the EDT, then the GUI becomes unresponsive - to everything - until the EDT is ... no longer held up.
    As I mentioned, because one of the purpose of a modal dialog is to keep the thread that made the dialog visible from continuing on (until the dialog is closed) then it would be in theory very bad to call JOptionPane.showXXX on the EDT as this would deadlock the program. Fortunately though, the java developers were kind enough to forsee this problem and implemented it so that a new temporary thread is created to handle the GUI stuff if a modal dialog is shown on the EDT.
    The bad news is that we can't really mimick this functionality on our own.
    Would I have to manually go through all of my components on the screen disabling them whenever I want to show a dialog if I did it this way or can I just block input to anything below the layer that the dialog in on?It could be as easy as making a component visible (like the glass pane) or as easy as calling a single method (when your content pane is wrapped within a JXLayer). You may not even need this functionality.
    I'm simply stating that the hard part is to design your code so that Point B no longer directly comes after showing the input prompt.
    Point A
    JOptionPane.showInputDialog(....);
    Point BThis can only be achieved by placing the input handling stuff (Point B) in a seperate method. One which is called by the component receiving input in a layer above the content pane.
    The JXLayer and the glass pane thing were simply to cut off functionality to the parent frame (the second purpose of a modal dialog).

Maybe you are looking for

  • Error message that I don't have permission

    I just updated to maverick and I don't have access to most of my folders, my desktop included.  There is a little red "do not enter" icon in the lower left corner of the folders.  Help!

  • Doubt in select options

    Hi frnds, Normally select option allowing only 8 charactor in declaration part, but i want to display with morethan 8 charator. i think some text id formet is there, how to do that. for ex, s_org for vbak-vkorg  . for this i want to give sales organi

  • Why is Finder (desktop) getting stuck on MacBookPro?

    I have OSX version 10.7.4 and my desktop keeps freezing while I am moving things from folder to folder. My browser will work, but nothing on my desktop, the wheel just keeps spinning. I have to shut the computer off and then have trouble restarting.

  • Xperia arc s

    when i update it to ics it's had been very hot when i use it more than 10 min what is the problem ??

  • Email Account Name Change

    Signed up to BT Infinity in June....before ordering i checked that i would be able to claim back my old btinternet email name that i used to have. The accoutn was dormant nad i wanted to use the same address. I was told it was easy......... However,