Class VTextFieldMenuItem

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants

public class VTextFieldMenuItem extends JMenuItem
Menu Item that displays a dialog box containing a VTextField with an optional message.

The VTextField is expected to implement the method VTextField.handleError() if the input can contain any errors. The implementation of this method should either correct the error or provide the user with enough information that the user will not assume that the value was changed. Some classes such as PortTextField have implemented this method in this way. The text field will respond to the ESCAPE character by aborting a change and keeping the previous value. The character RETURN (or ENTER) will accept the input as long as it is valid. An OK or CANCEL button can be used as alternatives. If the dialog box has a CLOSE button, clicking on that button will result in a dialog asking if the user intended to cancel the change. If the user pushes this dialog's "no" button, the user can continue editing the text field. When the dialog box becomes visible, the text field will have the keyboard focus.

The following code provides an example of how this class can be used:


 JFrame frame = ...;
 JMenubar menubar = ...;
 ...
 JMenu fileMenu = new JMenu("File");
 ...
 int port = 0;

 PortTextField ptf = new PortTextField(5) {
        public void onAccepted() throws Exception {
         super.onAccepted();
         port = getValue();
      }
 };
 ptf.setAllowEmptyTextField(true);
 pf.setDefaultValue(0);

 JMenuItem portMenuItem = new
    VTextFieldMenuItem(ptf, "HTTP Port", frame, "HTTP TCP Port"
                       "Please enter the TCP port to use:",
                       true);

 fileMenu.add(portMenuItem);
 ...
 menubar.add(fileMenu);
 
See Also:
  • Constructor Details

    • VTextFieldMenuItem

      public VTextFieldMenuItem(VTextField tf, String label, Dialog owner, String title, String msg, boolean modal)
      Constructor given a Dialog owner.
      Parameters:
      tf - the text field
      label - the menu label
      owner - the window on which a dialog box should be centered
      title - the dialog-box title
      msg - the message that will appear in the dialog box above the text field
      modal - true for a modal dialog; false otherwise
    • VTextFieldMenuItem

      public VTextFieldMenuItem(VTextField tf, String label, Frame owner, String title, String msg, boolean modal)
      Constructor given a Frame owner.
      Parameters:
      tf - the text field
      label - the menu label
      owner - the window on which a dialog box should be centered
      title - the dialog-box title
      msg - the message that will appear in the dialog box above the text field
      modal - true for a modal dialog; false otherwise
    • VTextFieldMenuItem

      public VTextFieldMenuItem(VTextField tf, String label, Window owner, String title, String msg, boolean modal)
      Constructor given a Window owner.
      Parameters:
      tf - the text field
      label - the menu label
      owner - the window on which a dialog box should be centered
      title - the dialog-box title
      msg - the message that will appear in the dialog box above the text field
      modal - true for a modal dialog; false otherwise
  • Method Details

    • dispose

      public void dispose()
      Free resources associated with this menu item. After this method is called, the menu item must not be used.