Package javax.swing

Examples of javax.swing.JFormattedTextField


    exprLabel = new JLabel("Regular Expression: ");
    validateLabel = new JLabel("Validate String: ");
    resultLabel = new JLabel("Result: ");

    exprField = new JFormattedTextField();
    exprField.setColumns(60);

    validateField = new JFormattedTextField();
    validateField.setColumns(60);

    resultField = new JFormattedTextField();
    resultField.setColumns(60);
    resultField.setEditable(false);
    resultField.setForeground(Color.red);

    exprLabel.setLabelFor(exprField);
View Full Code Here


    harness.checkPoint("(JSpinner)");
    JSpinner s = new JSpinner();
    JSpinner.NumberEditor e = new JSpinner.NumberEditor(s);
    harness.check(e.getLayout(), e);
    harness.check(e.getFormat(), NumberFormat.getInstance());
    JFormattedTextField ftf = e.getTextField();
    NumberFormatter nf = (NumberFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), null);
    harness.check(nf.getMaximum(), null);
   
    SpinnerNumberModel m = new SpinnerNumberModel(50.0, 0.0, 100.0, 5.0);
    s = new JSpinner(m);
    e = new JSpinner.NumberEditor(s);
    harness.check(e.getFormat(), NumberFormat.getInstance());
    ftf = e.getTextField();
    nf = (NumberFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), new Double(0.0));
    harness.check(nf.getMaximum(), new Double(100.0));
   
    // try null argument
    boolean pass = false;
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)
  {
    JFormattedTextField field = new JFormattedTextField();

    harness.checkPoint ("defaults");
    harness.check (((AbstractDocument)field.getDocument()).getDocumentFilter() == null);
    harness.check (field.getFormatterFactory() == null);
    harness.check (field.getFormatter() == null);


    harness.checkPoint ("implicit creation of formatter and factory");
    field.setValue("aBcDeFg");
    harness.check (((AbstractDocument)field.getDocument()).getDocumentFilter() != null);
    harness.check (field.getFormatterFactory().getClass(),
                   DefaultFormatterFactory.class);
    harness.check (field.getFormatter().getClass(), DefaultFormatter.class);
   

    harness.checkPoint ("setting formatter changes the text");
    MaskFormatter mask = null;
    DefaultFormatter nullFormatter = new DefaultFormatter();
    try
      {
        mask = new MaskFormatter ("UUUUUUU");
      }
    catch (ParseException pe)
      {
      }
    DefaultFormatterFactory factory =
      new DefaultFormatterFactory (mask, null, null, nullFormatter);
    harness.check (field.getText().equals("aBcDeFg"));
    field.setFormatterFactory(factory);
    harness.check (field.getText().equals("ABCDEFG"));

    harness.checkPoint ("field value going to null brings in nullFormatter");
    field.setValue(null);
    harness.check (field.getFormatter().getClass(), DefaultFormatter.class);       

    harness.checkPoint ("removing the DocumentFilter");
    field.getFormatter().uninstall();
    harness.check (((AbstractDocument)field.getDocument()).getDocumentFilter() == null);   
  }
View Full Code Here

    SpinnerDateModel m = new SpinnerDateModel();
    JSpinner s = new JSpinner(m);
    JSpinner.DateEditor e = new JSpinner.DateEditor(s);
    harness.check(e.getFormat(), DateFormat.getInstance());
    harness.check(e.getLayout(), e);
    JFormattedTextField ftf = e.getTextField();
    DateFormatter nf = (DateFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), null);
    harness.check(nf.getMaximum(), null);
   
    m = new SpinnerDateModel(new Date(50L), new Date(0L), new Date(100L),
            Calendar.MILLISECOND);
    s = new JSpinner(m);
    e = new JSpinner.DateEditor(s);
    harness.check(e.getFormat(), DateFormat.getInstance());
    ftf = e.getTextField();
    nf = (DateFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), new Date(0L));
    harness.check(nf.getMaximum(), new Date(100L));
   
    // try null argument
    boolean pass = false;
View Full Code Here

    pnlSizeX.setLayout(new BorderLayout(0, 0));

    lblSizeX = new JLabel("X: ");
    pnlSizeX.add(lblSizeX, BorderLayout.WEST);

    txtSizeX = new JFormattedTextField(nfSizeInt);
    txtSizeX.setFont(arial);
    txtSizeX.setText("1000");
    pnlSizeX.add(txtSizeX, BorderLayout.EAST);
    txtSizeX.setColumns(7);

    final JPanel pnlSizeZ = new JPanel();
    pnlSize.add(pnlSizeZ, BorderLayout.EAST);
    pnlSizeZ.setLayout(new BorderLayout(0, 0));

    lblSizeZ = new JLabel(" Z: ");
    pnlSizeZ.add(lblSizeZ, BorderLayout.WEST);

    txtSizeZ = new JFormattedTextField(nfSizeInt);
    txtSizeZ.setFont(arial);
    txtSizeZ.setText("1000");
    txtSizeZ.setColumns(7);
    pnlSizeZ.add(txtSizeZ, BorderLayout.EAST);

    final JPanel pnlSizeXZ = new JPanel();
    pnlSize.add(pnlSizeXZ, BorderLayout.NORTH);
    pnlSizeXZ.setLayout(new BorderLayout(0, 0));

    rdbtnSizeCustomSize = new JRadioButton("Custom Size:");
    rdbtnSizeCustomSize.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(final ActionEvent e) {

        SizeSetEnable(true);
      }
    });

    rdbtnSizeCustomSize.setSelected(true);
    pnlSizeXZ.add(rdbtnSizeCustomSize, BorderLayout.CENTER);

    final JPanel pnlSizeSquarify = new JPanel();
    pnlSize.add(pnlSizeSquarify, BorderLayout.SOUTH);
    pnlSizeSquarify.setLayout(new BorderLayout(0, 0));

    rdbtnSizeSquarify = new JRadioButton("Squarify Existing Land");
    rdbtnSizeSquarify.setToolTipText("Not Functional Yet...");
    rdbtnSizeSquarify.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(final ActionEvent e) {

        SizeSetEnable(false);
        CenterPointSetEnable(false);

      }
    });
    pnlSizeSquarify.add(rdbtnSizeSquarify, BorderLayout.CENTER);

    final JPanel pnlCenterPoint = new JPanel();
    pnlCenterPoint.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder("Center Point:"),
        BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    pnlOptions.add(pnlCenterPoint, BorderLayout.CENTER);
    pnlCenterPoint.setLayout(new BorderLayout(0, 0));

    final JPanel pnlCPrb = new JPanel();
    pnlCenterPoint.add(pnlCPrb, BorderLayout.NORTH);
    pnlCPrb.setLayout(new BorderLayout(0, 0));

    rdbtnCenterSpawnPoint = new JRadioButton("Spawn Point");
    rdbtnCenterSpawnPoint.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(final ActionEvent e) {

        CenterPointSetEnable(false);

      }
    });
    rdbtnCenterSpawnPoint.setSelected(true);
    pnlCPrb.add(rdbtnCenterSpawnPoint, BorderLayout.WEST);

    rdbtnCenterOther = new JRadioButton("Other:");
    rdbtnCenterOther.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(final ActionEvent e) {

        CenterPointSetEnable(true);

      }
    });
    pnlCPrb.add(rdbtnCenterOther, BorderLayout.EAST);

    final ButtonGroup bgCenterPoint = new ButtonGroup();
    bgCenterPoint.add(rdbtnCenterSpawnPoint);
    bgCenterPoint.add(rdbtnCenterOther);

    final JPanel pnlCPSelection = new JPanel();
    pnlCenterPoint.add(pnlCPSelection, BorderLayout.SOUTH);
    pnlCPSelection.setLayout(new BorderLayout(0, 0));

    final JPanel pnlCPx = new JPanel();
    pnlCPSelection.add(pnlCPx, BorderLayout.WEST);
    pnlCPx.setLayout(new BorderLayout(0, 0));

    lblCPX = new JLabel("X: ");
    lblCPX.setEnabled(false);
    pnlCPx.add(lblCPX, BorderLayout.WEST);

    txtCPX = new JFormattedTextField(nfCPInt);
    txtCPX.setFont(arial);
    txtCPX.setEnabled(false);
    txtCPX.setText("0");
    pnlCPx.add(txtCPX, BorderLayout.EAST);
    txtCPX.setColumns(7);

    final JPanel pnlCPz = new JPanel();
    pnlCPSelection.add(pnlCPz, BorderLayout.EAST);
    pnlCPz.setLayout(new BorderLayout(0, 0));

    lblCPZ = new JLabel("Z: ");
    lblCPZ.setEnabled(false);
    pnlCPz.add(lblCPZ, BorderLayout.WEST);

    txtCPZ = new JFormattedTextField(nfCPInt);
    txtCPZ.setEnabled(false);
    txtCPZ.setFont(arial);
    txtCPZ.setText("0");
    pnlCPz.add(txtCPZ, BorderLayout.EAST);
    txtCPZ.setColumns(7);
View Full Code Here

        BoxLayout.PAGE_AXIS));
    final JPanel pnlLocalPeer = new JPanel();
    pnlLocalPeer
        .setLayout(new BoxLayout(pnlLocalPeer, BoxLayout.PAGE_AXIS));
    pnlLocalPeer.add(new JLabel("Select port where to start peer:"));
    final JFormattedTextField localPort = new JFormattedTextField(
        new NumberFormatter());
    localPort.setValue(11111);
    pnlLocalPeer.add(localPort);
    final JPanel pnlMasterPeer = new JPanel();
    pnlMasterPeer.setLayout(new BoxLayout(pnlMasterPeer,
        BoxLayout.PAGE_AXIS));
    final JCheckBox connectMaster = new JCheckBox(
        "Should be connected with master peer?");
    pnlMasterPeer.add(connectMaster);
    final JPanel masterConfiguration = new JPanel();
    masterConfiguration.setLayout(new BoxLayout(masterConfiguration,
        BoxLayout.PAGE_AXIS));
    masterConfiguration.setVisible(false);
    pnlMasterPeer.add(masterConfiguration);
    connectMaster.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(final ActionEvent arg0) {
        //show master-configuration only if is to be connected to master peer
        masterConfiguration.setVisible(connectMaster.isSelected());
      }
    });
    masterConfiguration
        .add(new JLabel("Select master-port to connect to:"));
    final JFormattedTextField masterPort = new JFormattedTextField(
        new NumberFormatter());
    masterPort.setValue(11111);
    masterConfiguration.add(masterPort);
    masterConfiguration.add(new JLabel(
        "Select master-address/ip to connect to:"));
    final JTextField masterAddress = new JTextField();
    masterAddress.setText("127.0.0.1");
    masterConfiguration.add(masterAddress);
    createEvalatorPanel.add(pnlLocalPeer);
    createEvalatorPanel.add(pnlMasterPeer);

    /* Panel with JTable in the center */
    final JTable tbl = new JTable(model);
    final Border border = new TitledBorder(BorderFactory.createEtchedBorder(),
        "Select allready running evaluators", TitledBorder.LEADING,
        TitledBorder.TOP);
    final JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BorderLayout());
    tablePanel.setBorder(border);
    tablePanel.add(new JScrollPane(tbl), BorderLayout.CENTER);
    tablePanel.add(new JLabel(
        "Double-click on an evaluator, to use this instance."),
        BorderLayout.SOUTH);

    /* Panel on southern */
    final JPanel pnlControls = new JPanel();
    pnlControls.setLayout(new BoxLayout(pnlControls, BoxLayout.LINE_AXIS));
    pnlControls.setAlignmentX(Component.RIGHT_ALIGNMENT);
    final JButton ok = new JButton("OK");
    final JButton cancel = new JButton("Cancel");
    final JLabel label = new JLabel();
    label.setVisible(false);

    /*
     * listeners
     */
    tbl.addMouseListener(new MouseAdapter() {
      @Override
      public void mousePressed(final MouseEvent me) {
        final JTable table = (JTable) me.getSource();
        final Point p = me.getPoint();
        final int row = table.rowAtPoint(p);
        /*
         * On double-click of the table item ...
         */
        if (me.getClickCount() == 2) {
          final PeerItem eval = model.getItem(row);
          try {
            /*
             * ask whether this evaluator can be used
             */
            result[0] = P2PConfigFrame.this.onQueryEvaluator(eval);
          } catch (final Exception exception) {
            label.setText("Error: " + exception.getLocalizedMessage());
            label.setVisible(true);
            return;
          }
          //hide dialog
          frame.setVisible(false);
        }
      }
    });
    cancel.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(final ActionEvent e) {
        /*
         * inform and close dialog
         */
        P2PConfigFrame.this.onCancel();
        frame.setVisible(false);
      }
    });
    ok.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(final ActionEvent e) {
        int _localPort;
        int _masterPort;
        String _masterAddress;

        /* is input integer? */
        Object val = localPort.getValue();
        try {
          if (val instanceof Long) {
            _localPort = ((Long) val).intValue();
          } else if (val instanceof Integer) {
            _localPort = (Integer) val;
          } else {
            _localPort = Integer.parseInt((String) val);
          }
          if (_localPort > 65535 || _localPort < 0) {
            throw new NumberFormatException("Ports must be in [0,65535]");
          }
        } catch (final NumberFormatException exception) {
          label.setText("Error: " + exception.getLocalizedMessage());
          label.setVisible(true);
          return;
        }
        if (connectMaster.isSelected()) {
          /* is input integer? */
          val = masterPort.getValue();
          try {
            if (val instanceof Long) {
              _masterPort = ((Long) val).intValue();
            } else if (val instanceof Integer) {
              _masterPort = (Integer) val;
View Full Code Here

      oneTimeB = new JRadioButton("once: ", true);
      oneTimeB.addActionListener(this);
      timePanel.add(oneTimeB);

      // creates two Textfields to chose the wanted date and time
        dateFTF = new JFormattedTextField(new SimpleDateFormat("dd.MM.yyyy"))
        dateFTF.setValue(new Date()); // today as standard text
        timeFTF = new JFormattedTextField(new SimpleDateFormat("HH:mm"))
        timeFTF.setValue(new Date()); // now as standard text
      timePanel.add(dateFTF);
      timePanel.add(timeFTF);   

      // creates the period-Button
View Full Code Here

     * @see #getEditor()
     */
//    @Deprecated
    public void setEditor(JFormattedTextField editor) {
        Contract.asNotNull(editor, "editor must not be null");
        JFormattedTextField oldEditor = _dateField;
        _dateField = editor;
        firePropertyChange(EDITOR, oldEditor, _dateField);
    }
View Full Code Here

    text = GT._("width:")+" ";
    imageSizeWidth = new JLabel(text);
    text = GT._("Image width");
    imageSizeWidth.setToolTipText(text);
    imageSizeXYBox.add(imageSizeWidth);
    imageSizeTextWidth = new JFormattedTextField();
    imageSizeTextWidth.setValue(new Integer(outputWidth));
    imageSizeTextWidth.addPropertyChangeListener("value",
      new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
          imageSizeChanged();
          updateCommandLine();
        }
      }
    );
    imageSizeXYBox.add(imageSizeTextWidth);
    imageSizeXYBox.add(Box.createHorizontalStrut(10));
    text = GT._("height:")+" ";
    imageSizeHeight = new JLabel(text);
    text = GT._("Image height");
    imageSizeHeight.setToolTipText(text);
    imageSizeXYBox.add(imageSizeHeight);
    imageSizeTextHeight = new JFormattedTextField();
    imageSizeTextHeight.setValue(new Integer(outputHeight));
    imageSizeTextHeight.addPropertyChangeListener("value",
      new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
          imageSizeChanged();
View Full Code Here

    public String valueToString(final Object value) throws ParseException {
        return value != null ? value.toString() : "";
    }

    private Class getTextFieldValueClass() {
        JFormattedTextField textField = getFormattedTextField();
        if (textField == null) {
            return null;
        }
        Object value = getFormattedTextField().getValue();
        return value != null ? value.getClass() : null;
View Full Code Here

TOP

Related Classes of javax.swing.JFormattedTextField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.