List of usage examples for javax.swing JFormattedTextField JFormattedTextField
public JFormattedTextField(AbstractFormatterFactory factory)
JFormattedTextField
with the specified AbstractFormatterFactory
. From source file:FtfInputVerifier.java
public static void main(String argv[]) { java.net.URL u = null;// ww w . java 2 s . c om try { u = new java.net.URL("http://www.ora.com/"); } catch (java.net.MalformedURLException ignored) { } // create two identical JFormattedTextFields JFormattedTextField ftf1 = new JFormattedTextField(u); JFormattedTextField ftf2 = new JFormattedTextField(u); // and set an InputVerifier on one of them ftf2.setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof JFormattedTextField)) return true; // give up focus return ((JFormattedTextField) input).isEditValid(); } }); JPanel p = new JPanel(new java.awt.GridLayout(0, 2, 3, 8)); p.add(new JLabel("plain JFormattedTextField:", JLabel.RIGHT)); p.add(ftf1); p.add(new JLabel("FTF with InputVerifier:", JLabel.RIGHT)); p.add(ftf2); p.add(new JLabel("plain JTextField:", JLabel.RIGHT)); p.add(new JTextField(u.toString())); p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); JFrame f = new JFrame("FtfInputVerifier"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JLabel("Try to delete the colon in each field.", JLabel.CENTER), java.awt.BorderLayout.NORTH); f.getContentPane().add(p, java.awt.BorderLayout.CENTER); f.pack(); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;// w ww .j a v a 2 s . c om JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format currency = NumberFormat.getCurrencyInstance(Locale.UK); label = new JLabel("UK Currency:"); input = new JFormattedTextField(currency); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from w w w . jav a2s. com*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:JFormattedTextFieldDateInputSampleELocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;// w ww .j a v a2s. c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format dayOfWeek = new SimpleDateFormat("E", Locale.FRENCH); label = new JLabel("French day of week:"); input = new JFormattedTextField(dayOfWeek); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/*from ww w. java2 s . co m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format integer = NumberFormat.getIntegerInstance(Locale.ITALIAN); label = new JLabel("Italian integer:"); input = new JFormattedTextField(integer); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:JFormattedTextFieldDateInputSampleDateFormatFULLLocaleUS.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;// ww w. jav a 2 s . c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format fullUSDate = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); label = new JLabel("Full US date:"); input = new JFormattedTextField(fullUSDate); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:NumberInputNumberFormatgetInstance.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w ww .j ava 2 s . c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format general = NumberFormat.getInstance(); label = new JLabel("General/Instance:"); input = new JFormattedTextField(general); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:NumberInputSampleLocaleUK.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;/* w ww . j ava 2s . com*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format currency = NumberFormat.getCurrencyInstance(Locale.UK); label = new JLabel("UK Currency:"); input = new JFormattedTextField(currency); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:NumberFormatgetNumberInstanceLocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Number Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = new Font("SansSerif", Font.BOLD, 16); JLabel label;//from w w w .j av a2 s . c o m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format number = NumberFormat.getNumberInstance(Locale.FRENCH); label = new JLabel("French Number:"); input = new JFormattedTextField(number); input.setValue(2424.50); input.setColumns(20); input.setFont(font); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DateFormatter[] formatters = new DateFormatter[] { new DateFormatter(new SimpleDateFormat("dd.MM.yyyy")), new DateFormatter(new SimpleDateFormat("ddMMyyyy")), new DateFormatter(new SimpleDateFormat("yyyy.MM.dd.")), new DateFormatter(new SimpleDateFormat("dd.MMM.yyyy")), new DateFormatter(new SimpleDateFormat("dd/MM/yyyy")) }; MultiFormatter<DateFormatter> multiFormatter = new MultiFormatter<>(formatters); JFormattedTextField ftf = new JFormattedTextField(multiFormatter); ftf.setColumns(10);/*from w ww .j ava2s.com*/ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(ftf); frame.add(new JButton("OK")); frame.pack(); frame.setVisible(true); }