Buscar este blog

miércoles, 21 de abril de 2010

JOptionPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JOptionPane


Sirve para los cuadros de dialogos. Hace que sea fácil para que aparezca un cuadro de diálogo estándar que pide a los usuarios un valor o les informa de algo. Mientras que la clase JOptionPane puede parecer compleja debido a la gran cantidad de métodos, casi todos los usos de esta clase son las llamadas a los métodos estáticos showxxxdialog que se muestran a continuación 
Method Name                     Description  
showConfirmDialog          Asks a confirming question like yes/no/cancel.  
showInputDialog               Promt for some input.
showMessageDialog         Tell the user about something that has happened  
showOptionDialog            The unification of the above three.  

La apariencia básica de un cuadro de dialogo en java a pesar de los Look-and-Feels es como se ve en la siguiente figura.

Los parámetros de los métodos antes mencionados 
  • parentComponent Define el componente que es el parent(padre) del cuadro de dialogo. Este parámetro puede ser null, en cuyo caso se centra en la pantalla y no depende de ningún frame.
  • message A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. Its interpretation depends on its type:
    • Object[] An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.
    • Component The Component is displayed in the dialog.
    • Icon The Icon is wrapped in a JLabel and displayed in the dialog.
    • others The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed.
  • message Type Defines the style of the message. The Look and Feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:
    • ERROR_MESSAGE
    • INFORMATION_MESSAGE
    • WARNING_MESSAGE
    • QUESTION_MESSAGE
    • PLAIN_MESSAGE
  • option Type Defines the set of option buttons that appear at the bottom of the dialog box.You aren't limited to this set of option buttons. You can provide any buttons you want using the options parameter:
    • DEFAULT_OPTION
    • YES_NO_OPTION
    • YES_NO_CANCEL_OPTION
    • OK_CANCEL_OPTION
  • options A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on its type:
    • Component The component is added to the button row directly.
    • Icon A JButton is created with this as its label.
    • other The Object is converted to a string using its toString method and the result is used to label a JButton.
  • icon A decorative icon to be placed in the dialog box. A default value for this is determined by the messageType parameter.
  • title The title for the dialog box.
  • initial Value The default selection (input value).

Ejemplos


No hay comentarios:

Publicar un comentario