|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-27-2008, 05:55 PM
|
|
Member
|
|
Join Date: Mar 2008
Posts: 20
|
|
|
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?
|
|

05-27-2008, 08:13 PM
|
|
Member
|
|
Join Date: Apr 2007
Location: USA
Posts: 50
|
|
#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.
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 :
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
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-28-2008, 12:55 PM
|
|
Member
|
|
Join Date: Mar 2008
Posts: 20
|
|
|
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
JOptionPane.showMessageDialog(MyRequest, "You have not selected details of what you want to know!", JOptionPane.WARNING_MESSAGE);
but it still didn't work!
|
|

05-28-2008, 02:00 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
|
You may look at JOptionPane class....
eg.
showMessageDialog(null,"Message","Title",int constant);
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-28-2008, 03:31 PM
|
 |
Member
|
|
Join Date: Apr 2007
Location: Midwest
Posts: 60
|
|
|
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.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-29-2008, 03:10 PM
|
|
Member
|
|
Join Date: Mar 2008
Posts: 20
|
|
|
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!
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|