KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > swing > JOptionPane

javax.swing
Class JOptionPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JOptionPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
See Also:
Top Examples, Source Code, XMLEncoder, JInternalFrame

public static final int CANCEL_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[885]How to do the codes for the cancel button of a input option dialog
By ngpamela { at } hotmail { dot } com (Pamela) on 2005/02/28 17:48:20  Rate
    if  ( JOptionPane.CANCEL_OPTION == true )   {   
       JOptionPane.showOptionDialog ( null, "Please choose an option", "Library System", 
            JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, choice, 
            "List Borrowers" ) ; 
      }  
  
  
 How to do the codes for the cancel button of a input option dialog and return to the main option dialog pane?


[1989]How to cancel information in the database with the use of java program
By dearie_sweet { at } yahoo { dot } com { dot } ph on 2009/01/27 03:32:36  Rate
please help!

public static final int CLOSED_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JDialog createDialog(Component parentComponent,
                            String title)
                     throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JInternalFrame createInternalFrame(Component parentComponent,
                                          String title)
See Also:
RuntimeException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int DEFAULT_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int ERROR_MESSAGE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[899]The last character pressed
By Anonymous on 2004/12/21 16:29:21  Rate
public void keyPressed ( KeyEvent e )  
                   {  
                         char a [  ] ; 
                         a=new char [ 3 ] ; 
                         a [ i ] =e.getKeyChar (  ) ; 
                         i++; 
                         if ( i==3 )  
                         JOptionPane ( JFrame,"u need to enter only three digit value",WARNING_MESSAGE,2 ) ; 
                         else 
                         JOptionPane ( sampleframe,"u need not enter", WARNING_MESSAGE,2 ) ; 
  
  
                          }  
                         public void KeyReleased ( KeyEvent e )  
                          {  
                                 char souji; 
                                 souji=e.getKeyChar (  ) ; 
  
  
                                 System.out.println ( "The last character is " + souji ) ; 
                          } 


public AccessibleContext getAccessibleContext()
See Also:
JComponent, Accessible
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Frame getFrameForComponent(Component parentComponent)
                                  throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[127]If you have a component (JPanel, JButton, etc) and want to find the frame it is contained in
By Anonymous on 2003/01/09 08:55:06  Rate
If you have a component  ( JPanel, JButton, etc )  and want to find the frame it is contained in. 
  
  
 public void displayDialog ( Component component )   {  
   // Create a modal dialog. JDialog needs a Frame as a 
   // parameter to its constructor, so use 'getFrameForComponent' 
   JDialog myDailog = new JDialog (  
                    JOptionPane.getFrameForComponent ( component ) , 
                    "This is my modal dailog", 
                    true ) ; 
  
  
   // Show the dialog and do anything else needed... 
  }  
  
  
 This is a very simple example, but I have found this method very 
 usefull when creating custom dialog boxes and only have access to 
 a component. Look in JOptionPane code to see how the Frame is 
 found using the component.


public Icon getIcon()
See Also:
setIcon(javax.swing.Icon)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getInitialSelectionValue()
See Also:
setSelectionValues(java.lang.Object[]), setInitialSelectionValue(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getInitialValue()
See Also:
setInitialValue(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getInputValue()
See Also:
setInputValue(java.lang.Object), setWantsInput(boolean), setSelectionValues(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getMaxCharactersPerLineCount()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[506]Message Dialog
By arbaken on 2004/05/28 04:40:07  Rate
JOptionPane op = new JOptionPane ( textGraph1 )   {  
        public int getMaxCharactersPerLineCount (  )   {  
         return 5; 
        }  
        } ; 
  
  
       op.showMessageDialog ( null,textGraph1 ) ;


public Object getMessage()
See Also:
setMessage(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getMessageType()
See Also:
setMessageType(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object[] getOptions()
See Also:
setOptions(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getOptionType()
See Also:
setOptionType(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Frame getRootFrame()
                          throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object[] getSelectionValues()
See Also:
setSelectionValues(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public OptionPaneUI getUI()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getUIClassID()
See Also:
UIDefaults.getUI(javax.swing.JComponent), JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object getValue()
See Also:
setValue(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getWantsInput()
See Also:
setWantsInput(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Icon icon
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String ICON_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int INFORMATION_MESSAGE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object initialSelectionValue
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object initialValue
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String INITIAL_SELECTION_VALUE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String INITIAL_VALUE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object inputValue
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String INPUT_VALUE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1380]_
By Anonymous on 2005/04/05 13:57:51  Rate
JFrame frame=new JFrame (  ) ; 
 JOptionPane.showMessageDialog ( frame,"test" ) ;


public JOptionPane(Object message)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane(Object message,
                   int messageType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane(Object message,
                   int messageType,
                   int optionType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon,
                   Object[] options)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon,
                   Object[] options,
                   Object initialValue)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object message
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected int messageType
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String MESSAGE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String MESSAGE_TYPE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int NO_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int OK_CANCEL_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int OK_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object[] options
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String OPTIONS_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected int optionType
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String OPTION_TYPE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected String paramString()
See Also:
JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[793]A Frame with applet inside
By saurabhagarwal { at } 4cplus { dot } com on 2004/05/28 03:09:25  Rate
import java.applet.Applet;  
   import java.awt.*;  
   import java.awt.event.*;  
 /* < applet code="hello4" width=200 height=200 >  
  < /applet > */
 
 public class hello4 extends Applet  {   
     public void init (  )  {   
            add ( new myButton ( "BBB" )  ) ;  
                        }   
      public void paint ( Graphics screen )  
       {       }   
  
  
 class myButton extends Button 
  {   
        myButton ( String label )  
         {   
             super ( label ) ;  
              }   
         public String paramString (  )  {   
              return super.paramString (  ) ;  
            }   
    }  
  
  
   public static void main ( String [  ]  args )  {   
    Frame myFrame = new Frame ( "Copyright Amit" ) ;  
       myFrame.setSize ( 300,100 ) ;  
      Applet myApplet = new hello4 (  ) ;  
      Button b = new Button ( "My Button" ) ;  
      myApplet.add ( b ) ;  
      b.setLabel ( b.getLabel (  ) +"New" ) ;  
    Button b1 = new Button ( "PARAMBUTTON" ) . 
 // myButton b1 = ( new hello4 (  )  ) .new myButton ( "PARAMBUTTON" ) ;  
  
  
      System.out.println ( b1.paramString (  )  ) ;  
      myFrame.add ( myApplet ) ;  
      myFrame.setVisible ( true ) ;  
      myFrame.addWindowListener ( new WindowAdapter (  )  {   
      public void windowClosing ( WindowEvent e )  
       {   
            System.exit ( 0 ) ; 
         }  }  ) ;  
     }   
  } 


public static final int PLAIN_MESSAGE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int QUESTION_MESSAGE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void selectInitialValue()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object[] selectionValues
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String SELECTION_VALUES_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setIcon(Icon newIcon)
See Also:
getIcon()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setInitialSelectionValue(Object newValue)
See Also:
getInitialSelectionValue(), setSelectionValues(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setInitialValue(Object newInitialValue)
See Also:
getInitialValue()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setInputValue(Object newValue)
See Also:
getInputValue(), setWantsInput(boolean), setInitialSelectionValue(java.lang.Object), setSelectionValues(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setMessage(Object newMessage)
See Also:
getMessage()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setMessageType(int newType)
See Also:
getMessageType(), RuntimeException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setOptions(Object[] newOptions)
See Also:
getOptions()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setOptionType(int newType)
See Also:
setOptions(java.lang.Object[]), getOptionType(), RuntimeException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setRootFrame(Frame newRootFrame)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setSelectionValues(Object[] newValues)
See Also:
getSelectionValues(), setInitialSelectionValue(java.lang.Object), setWantsInput(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setUI(OptionPaneUI ui)
See Also:
UIDefaults.getUI(javax.swing.JComponent)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setValue(Object newValue)
See Also:
getValue()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setWantsInput(boolean newValue)
See Also:
setInputValue(java.lang.Object), setSelectionValues(java.lang.Object[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showConfirmDialog(Component parentComponent,
                                    Object message)
                             throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType)
                             throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType,
                                    int messageType)
                             throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType,
                                    int messageType,
                                    Icon icon)
                             throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInputDialog(Component parentComponent,
                                     Object message)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[859]Simple Input Dialog
By kor { at } axiomsol { dot } com on 2004/08/18 06:24:29  Rate
import java.io.*; 
 import java.awt.*; 
 import java.awt.event.*; 
 import javax.swing.*; 
 import java.util.Enumeration; 
  
  
 import  javax.swing.JOptionPane; 
 public  class  smsg 
  {  
         private FlowLayout layout; 
         private Container c; 
         private JButton left; 
  
  
         public static void main ( String [  ]  args )  
          {        String data; 
                 data = show_input_dialog (  ) ; 
                 System.out.println ( data ) ; 
          }  
  
  
         public static  String show_input_dialog (  )  
          {  
                 String data; 
                 data = JOptionPane.showInputDialog ( "Testing" ) ; 
                 return data; 
          }  
         public  void layout (  )  
          {  
                 layout = new FlowLayout (  ) ; 
                 c = getContentPane (  ) ; 
                 c.setLayout ( layout ) ; 
                 layout.show (  ) ; 
          }  
  
  
  
  }  
 


public static String showInputDialog(Component parentComponent,
                                     Object message,
                                     Object initialSelectionValue)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInputDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Object showInputDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType,
                                     Icon icon,
                                     Object[] selectionValues,
                                     Object initialSelectionValue)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInputDialog(Object message)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInputDialog(Object message,
                                     Object initialSelectionValue)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType,
                                            int messageType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showInternalConfirmDialog(Component parentComponent,
                                            Object message,
                                            String title,
                                            int optionType,
                                            int messageType,
                                            Icon icon)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInternalInputDialog(Component parentComponent,
                                             Object message)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String showInternalInputDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Object showInternalInputDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType,
                                             Icon icon,
                                             Object[] selectionValues,
                                             Object initialSelectionValue)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void showInternalMessageDialog(Component parentComponent,
                                             Object message)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void showInternalMessageDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void showInternalMessageDialog(Component parentComponent,
                                             Object message,
                                             String title,
                                             int messageType,
                                             Icon icon)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showInternalOptionDialog(Component parentComponent,
                                           Object message,
                                           String title,
                                           int optionType,
                                           int messageType,
                                           Icon icon,
                                           Object[] options,
                                           Object initialValue)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void showMessageDialog(Component parentComponent,
                                     Object message)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void showMessageDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[186]Display an information message
By Anonymous on 2003/03/18 18:54:50  Rate
JOptionPane.showMessageDialog ( null, output ,"KickJava",JOptionPane.INFORMATION_MESSAGE  ) ;

public static void showMessageDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType,
                                     Icon icon)
                              throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int showOptionDialog(Component parentComponent,
                                   Object message,
                                   String title,
                                   int optionType,
                                   int messageType,
                                   Icon icon,
                                   Object[] options,
                                   Object initialValue)
                            throws HeadlessException
See Also:
GraphicsEnvironment.isHeadless()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final Object UNINITIALIZED_VALUE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void updateUI()
See Also:
JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected transient Object value
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String VALUE_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected boolean wantsInput
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final String WANTS_INPUT_PROPERTY
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int WARNING_MESSAGE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int YES_NO_CANCEL_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int YES_NO_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[923]Display a question message
By goodboy2005 { at } hotmail { dot } com on 2004/09/23 18:19:59  Rate
import javax.swing.JOptionPane; 
  
  
 public class Gente {  
   String nombre, sexo; 
   int edad; 
   public Gente (  )  {  
     nombre = ""; sexo = ""; 
     edad = 0; 
    }  
  
  
   public String setNombre (  )  {  
     String n = ""; 
     n = "??Escriba su nombre por favor!! "; 
     nombre = JOptionPane.showInputDialog ( null,n,"Junta de Protecci??n Social de San Jos??",JOptionPane.QUESTION_MESSAGE ) ; 
     return nombre; 
    }  
  
  
   public String setGenero (  )  {  
     String s = ""; //boolean yes = true; 
     s = "Si eres hombre da clic en: \"si\" y si eres mujer da clic en: \"no\"."; 
     sexo = JOptionPane.showInputDialog ( null,s,"Junta de Protecci??n Social de San Jos??",JOptionPane.YES_NO_OPTION ) ; 
      
     /*if  ( JOptionPane.CANCEL_OPTION == true )  {  // ( compareTo ( Yes )  == 0  )  {  
       sexo += "Se??or "; 
      }  
     else {  
       sexo += "Se??ora ( ita )  "; 
      } */
 
     return sexo; 
    }  
  
  
    
   public int setEdad (  )  {  
     String e =""; 
     e = "??Digite su edad  ( en n??meros del 0-99 ) !!"; 
     edad = Integer.parseInt ( JOptionPane.showInputDialog ( null,e,"Junta de Protecci??n Social de San Jos??",JOptionPane.QUESTION_MESSAGE )  ) ; 
     return edad; 
    }  
  
  
  } 


public static final int YES_OPTION
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags