• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Very basic question about J.OptionPane.showMessageDialog method

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm trying to understand how to read (i.e., how to translate from geek speak to English) the overwhelming and detailed Java API as I'm learning how to code. Regarding this method I copied from the API:

static String showInputDialog(Object message)
Shows a question-message dialog requesting input from the user.


In "English", this method is a class static method that returns a String type and the method's argument is the class's field message? So how does "Object" come into play here? I understand Object is the root class (of all classes) but I don't understand its relationship to "message" because isn't message a field for J.OptionPane class?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The message is of type object because it doesn't have to be a String. You can pass a String[] which will be shown as all Strings below each other, and even complete Components like JTextField, JButton, JPanel, etc.

Although the actual supported Object types are not clearly documented, a little investigation showed that the following are allowed:
- Component: the component will be added
- Icon: a text-less label with the icon will be added
- Object[]: all elements of the array are added using the same code, so the Object[] can contain Component, Icon, Object[], etc
- anything else will be converted into a String which is added as a label
 
Karen Haq
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I think I got.
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic