Results 1 to 6 of 6
  1. #1
    themburu is offline Member
    Join Date
    Mar 2008
    Posts
    20
    Rep Power
    0

    Default String array for Choice, JOptionPane doesn't show

    1.Is there a way that you can make the choicelist use a string array, the thing is that I want the contents of the choice list to change to suite what is selected in my checkboxes, I find the lengthy addItem awkward and hard to replace in this case.

    2.I also wanted to show a message dialog, I imported the necessary class import javax.swing.JOptionPane;

    but when i used it in my code it gave an error

    JOptionPane.showMessageDialog(null, "You have not selected details of what you want to know!", JOptionPane.WARNING_MESSAGE);

    How do you show the message dialog?

  2. #2
    derrickD is offline Member
    Join Date
    Apr 2007
    Location
    USA
    Posts
    50
    Rep Power
    0

    Default

    #1. The answer is yes. Make your StringArray then just use a loop to add the items, you do not have to do any tedious work of addItem then.
    Java Code:
    String[] myArray = {"A","B","C"};
    for (int i = 0; i < myArray.length; i++) {
    			
    myChoiceList.add(myArray[i]);
    }
    #2. JOption pane needs the parent as the first parameter. You have null.
    So, it should be :
    Java Code:
    JOptionPane.showMessageDialog(myParentComponent(), "You have not selected details of what you want to know!", JOptionPane.WARNING_MESSAGE);
    with "myParentComponent()" being the name of the component that is calling the JOptionpane

  3. #3
    themburu is offline Member
    Join Date
    Mar 2008
    Posts
    20
    Rep Power
    0

    Default I had tried the myParentComponent() which is MyRequest

    I Will try the loop,

    but for the JOptionPane I had tried that i.e myParentComponent(), Actually the name of the applet is MyRequest so I had
    Java Code:
    JOptionPane.showMessageDialog(MyRequest, "You have not selected details of what you want to know!", JOptionPane.WARNING_MESSAGE);
    but it still didn't work!

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    You may look at JOptionPane class....

    eg.

    showMessageDialog(null,"Message","Title",int constant);
    freedom exists in the world of ideas

  5. #5
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Isn't there a subcomponent for your applet, like a JFrame or a JPanel?? That is the component you should put in there, the component that actually has the button on it or whatever it is that makes the JOption pane popup. You do not list the applet, you list a Component. Please look at the Java API for JOptionPane and that should help out.

  6. #6
    themburu is offline Member
    Join Date
    Mar 2008
    Posts
    20
    Rep Power
    0

    Default It works Thanx/Asante!

    Men it work fine, Thanks, Asante is thanks in kiswahili.

    Actually since the applet is itself acontainer you have to included all the parts of the JOptionPane, ie

    showMessageDialog(null,"Message","Title",int constant);

    Again Asante.
    The dream of being a legend has just begun!

Similar Threads

  1. How i add string array in vector
    By susan in forum New To Java
    Replies: 7
    Last Post: 02-12-2009, 02:32 PM
  2. Need Help with String Array
    By crazydeo in forum New To Java
    Replies: 1
    Last Post: 05-13-2008, 10:18 AM
  3. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM
  4. String []Array
    By Warren in forum New To Java
    Replies: 4
    Last Post: 12-01-2007, 09:03 AM
  5. Replies: 1
    Last Post: 08-03-2007, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •