Results 1 to 9 of 9
- 03-28-2009, 02:09 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
help with JOptionPane.showMessageDialog()
hi can someone please help me with JOptionPane.showMessageDialog();
all i want to do is set the dialog visible when a button is clicked. it must display a message, have the warning icon in the corner and have an option to click either yes or no buttons in the dialog. also i would like to write further code for when each of the butons are clicked.
this is my code, its not working
JOptionPane.showMessageDialog(null,"Are you sure you want to delete: " + selected, "Warning", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
please help.
much appreciated
- 03-28-2009, 02:19 PM #2
What is the problem your seeing? What is not working? Imagine taking your car to the mechanic and saying "It's not working".... not much information for him to fix it.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
-
My guess: you've got a problem with the button's action listener, either it's not set up correctly or it has not been added to the button,... but this is only a SWAG. As Chris correctly points out, you'd do well to provide us with more detail, a lot more detail.
Best of luck.
- 03-28-2009, 05:13 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think he wants to pop-up a message box on a click event and depend on the message result want to handle the dialog/frame. Not clear on me too.
- 03-29-2009, 10:23 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
ok soz the error says: cannot find symbol : method showMessageDialog(<nulltype>,java.lang.String,java .lang.String,int,int)
but i got that code from the java tutorial website: java.sun.com/docs/books/tutorial/uiswing/components/dialog.html]How to Make Dialogs (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)
the original is:
final JOptionPane optionPane = new JOptionPane(
"The only way to close this dialog is by\n"
+ "pressing one of the following buttons.\n"
+ "Do you understand?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);
all i did was swap words to get what i wanted but it gives me that error message^^^.
in my code...
JOptionPane.showMessageDialog(null,"Are you sure you want to delete: " + selected, "Warning", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
i even tried to take out the JOptionPane.WARNING_MESSAGE so that JOptionPane.YES_NO_OPTION was left, i ran the program and the message dialog did not have a yes no option, it just had a "ok" option.
yes eranga, u do have an idea, also i dont know how to get the action listener of the clicked button so i can write code to act on that
if there is anything else you need to help me i will glady provide it.
thnx
much appreciated
- 03-29-2009, 10:14 PM #6
What made you add a null as the first parameter? The tutorial example you posted doesn't have that!
And take a look at JOptionPane#showOptionDialog, it returns an int value by which you can determine which button was clicked, and take action accordingly. Read the API for the method to see what parameters it takes.
Adding ActionListeners to a JOptionPane's buttons is a non-trivial exercise.
db
- 03-30-2009, 05:30 AM #7
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
there exist 3 showMessageDialog method
showMessageDialog(Component parentComponent, Object message)
showMessageDialog(Component parentComponent, Object message, String title, int messageType)
showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
what you use is
showMessageDialog(Component parentComponent,java.lang.String,java .lang.String,int,int)
which not one of above 3 method
the original you stated was constructor, not a static method of the class
i suggest to use a constructor if you want to use JOptionPane.QUESTION_MESSAGE with JOptionPane.YES_NO_OPTIONLast edited by mtyoung; 03-30-2009 at 05:35 AM.
- 03-30-2009, 07:39 AM #8
Member
- Join Date
- Feb 2009
- Posts
- 46
- Rep Power
- 0
Probably best creating a JFrame and putting the dialog into that frame where 'null' is.
- 03-30-2009, 09:31 AM #9
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
thnx 4 help and effort but figured it out. my code is:
int answer = JOptionPane.showConfirmDialog(null, "Are You Sure You Want to Delete: " + selected + "?", "Are you Sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.YES_OPTION) {
System.out.println("Deleted");}
Similar Threads
-
Sick of duplicating JOptionPane.showMessageDialog
By gdanelian in forum New To JavaReplies: 2Last Post: 11-18-2008, 05:53 PM -
No meesage display for JOptionPane.showMessageDialog in VnC or Solaris
By quest4qwerty in forum AWT / SwingReplies: 1Last Post: 10-29-2008, 07:50 AM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum AWT / SwingReplies: 2Last Post: 11-02-2007, 10:45 PM -
About JOptionPane.showMessageDialog
By jhetfield18 in forum Advanced JavaReplies: 0Last Post: 11-02-2007, 10:56 AM -
Displaying numbers per line on a JOptionPane.showMessageDialog screen
By zoe in forum New To JavaReplies: 1Last Post: 07-31-2007, 04:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks