Java JFormattedTextField set column width

Description

Java JFormattedTextField set column width

import java.awt.BorderLayout;
import java.awt.Font;
import java.util.Date;

import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main {
   public static void main(final String args[]) {
      JFrame frame = new JFrame("Formatted Example");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JFormattedTextField input = new JFormattedTextField(1234.50);
      input.setValue(123321);/*from   ww  w  . j  a  v a 2s.  c  o  m*/
      input.setColumns(20);
      input.setFont(new Font("SansSerif", Font.BOLD, 16));

      frame.add(input, BorderLayout.NORTH);

      frame.add(new JTextField(), BorderLayout.SOUTH);
      frame.setSize(250, 100);
      frame.setVisible(true);
   }
}



PreviousNext

Related