public class MaskFormatterTest { private static final DateFormat df = new SimpleDateFormat("yyyy/mm/dd"); public static void main(String[] args) { JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JFormattedTextField tf = new JFormattedTextField(df); tf.setColumns(20); panel.add(tf); try { MaskFormatter dateMask = new MaskFormatter("####/##/##"); dateMask.install(tf); } catch (ParseException ex) { Logger.getLogger(MaskFormatterTest.class.getName()).log(Level.SEVERE, null, ex); } frame.add(panel); frame.pack(); frame.setVisible(true); } }
public TimeoutGUI() { rows = Timeout.getTimeoutsJava().entrySet().stream().map(e -> { NumberFormat format = NumberFormat.getInstance(); NumberFormatter formatter = new NumberFormatter(format); format.setGroupingUsed(false); formatter.setValueClass(Integer.class); formatter.setMinimum(0); formatter.setAllowsInvalid(true); formatter.setMaximum(Integer.MAX_VALUE); final JFormattedTextField field = new JFormattedTextField(formatter); field.setToolTipText(FIELD_TOOLTIP); field.setText(e.getValue().toString()); return new AbstractMap.SimpleEntry<>(e.getKey(), field); }).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); rootPanel = createRootPanel(); }
versionPanel.setMaximumSize(new Dimension(2000, 31)); versionPanel.add(new JLabel(" Smack version: ")); JFormattedTextField field = new JFormattedTextField(SmackConfiguration.getVersion()); field.setEditable(false); field.setBorder(null);
label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); JFormattedTextField field = new JFormattedTextField(connection.getXMPPServiceDomain()); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); field = new JFormattedTextField(connection.getPort()); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); userField = new JFormattedTextField(); userField.setMinimumSize(new java.awt.Dimension(150, 20)); userField.setMaximumSize(new java.awt.Dimension(150, 20)); label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SS")); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); statusField = new JFormattedTextField(); statusField.setMinimumSize(new java.awt.Dimension(150, 20)); statusField.setMaximumSize(new java.awt.Dimension(150, 20));
final JLabel nowLabel = new JLabel("Present index: " + selectedIndex); final JLabel label = new JLabel("Index to go:"); final JTextField field = new JFormattedTextField(NumberFormat.getIntegerInstance()); field.setPreferredSize(new Dimension(100, 20));
private void createUIComponents() { NumberFormat format = NumberFormat.getIntegerInstance(); NumberFormatter numberFormatter = new NumberFormatter(format); numberFormatter.setValueClass(Integer.class); numberFormatter.setAllowsInvalid(false); numberFormatter.setMinimum(1); numberFormatter.setCommitsOnValidEdit(true); targetHeight = new JFormattedTextField(numberFormatter); targetWidth = new JFormattedTextField(numberFormatter); targetRoot = new FileBrowserField(FileBrowserField.RESOURCE_DIR_CHOOSER); } }
if (this.vrp != null) noJobs = this.vrp.getJobs().values().size(); JFormattedTextField nJobs = new JFormattedTextField(noJobs); nJobs.setFont(font); nJobs.setEditable(false); costs.setPreferredSize(new Dimension((int) (40 * scaling), (int) (25 * scaling))); JFormattedTextField costsVal = new JFormattedTextField(getSolutionCosts()); costsVal.setFont(font); costsVal.setEditable(false); JFormattedTextField vehVal = new JFormattedTextField(getNoRoutes()); vehVal.setFont(font); vehVal.setEditable(false);
public static JFormattedTextField createIntegerField(int minValue, int maxLength) { IntegerFormatter formatter = new IntegerFormatter(minValue); JFormattedTextField field = new JFormattedTextField(formatter); field.setHorizontalAlignment(JTextField.CENTER); field.addKeyListener(new FieldListener(maxLength)); return field; }
nameField = new JFormattedTextField(20); nameField.setEnabled(false); addRow("Name", nameField);
final JFormattedTextField timeField = new JFormattedTextField(mask);
float minutes = 100.5f; // 1:40:30 Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.add(Calendar.MINUTE, (int) minutes); c.add(Calendar.SECOND, (int) ((minutes % (int) minutes) * 60)); final Date date = c.getTime(); Format timeFormat = new SimpleDateFormat("HH:mm:ss"); JFormattedTextField input = new JFormattedTextField(timeFormat); input.setValue(date);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.getDefault()); DecimalFormat decimalFormat = (DecimalFormat) numberFormat; decimalFormat.setGroupingUsed(false); deg = new JFormattedTextField(decimalFormat); deg.setColumns(15); //whatever size you wish to set
NumberFormat amountFormat = NumberFormat.getNumberInstance(); amountFormat.setMinimumIntegerDigits(1); amountFormat.setMaximumIntegerDigits(3); amountFormat.setMaximumFractionDigits(0); amountField = new JFormattedTextField(amountFormat);
// Define the number factory. NumberFormat nf = NumberFormat.getIntegerInstance(); // Specify specific format here. NumberFormatter nff = new NumberFormatter(nf); DefaultFormatterFactory factory = new DefaultFormatterFactory(nff); // Define the decimal factory. DecimalFormat df = new DecimalFormat(); // And here.. NumberFormatter dnff = new NumberFormatter(df); DefaultFormatterFactory factory2 = new DefaultFormatterFactory(dnff); // Then you set which factory to use. JFormattedTextField field = new JFormattedTextField(); field.setFormatterFactory(factory); //field.setFormatterFactory(factory2);
protected void createEditor() { $objectMap.put("editor", editor = new JFormattedTextField()); editor.setName("editor"); editor.setColumns(15); }
/** * This method initializes radiusRetriesTextField * * @return javax.swing.JTextField */ private JFormattedTextField getRadiusRetriesTextField() { if (radiusRetriesTextField == null) { radiusRetriesTextField = new JFormattedTextField(getNumberFormatter()); radiusRetriesTextField.setValue(new Integer(0)); } return radiusRetriesTextField; }
/** * This method initializes radiusInterimIntervalTextField * * @return javax.swing.JTextField */ private JFormattedTextField getRadiusInterimIntervalTextField() { if (radiusInterimIntervalTextField == null) { radiusInterimIntervalTextField = new JFormattedTextField(getNumberFormatter()); radiusInterimIntervalTextField.setValue(new Integer(60)); } return radiusInterimIntervalTextField; }
private JFormattedTextField getFormattedTextField(int amount) { JFormattedTextField result = new JFormattedTextField(NumberFormat.getNumberInstance()); result.setValue(new Integer(amount)); result.setColumns(10); result.setPreferredSize(new Dimension(90, 18)); result.setMinimumSize(new Dimension(90, 18)); result.setMaximumSize(new Dimension(90, 18)); result.addKeyListener(enablingKeyListener); return result; } }
protected void createEditor() { $objectMap.put("editor", editor = new JFormattedTextField()); editor.setName("editor"); editor.setColumns(15); editor.addKeyListener(JAXXUtil.getEventListener(KeyListener.class, "keyReleased", this, "doKeyReleased__on__editor")); }
private Dimension getCompareMinimumSize() { JFormattedTextField field = new JFormattedTextField(getFormatter()); field.setMargin(getMargin()); field.setBorder(getBorder()); field.setFont(getFont()); field.setValue(new Date()); Dimension min = field.getPreferredSize(); field.setValue(null); min.width += Math.max(field.getPreferredSize().width, 4); return min; }