Home / ພື້ນຖານ Desktop app / GUI_Component / JFormattedTextField
ສຳລັບ Formatted TextField ຫຼື JFormattedTextField (javax.swing.JFormattedTextField) ຈັດຢູ່ໃນກຸ່ມຂອງ Component ໂດຍວັດຖຸປະສົງຄືໃຊ້ຈັດຮູບແບບ Format ຂອງ Input ຕ່າງ ໆ ເຊັ່ນ Input ແບບ Date Format , Number Format , Telephone Format ແລະ ອື່ນໆ
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay Java");
setLayout(null);
// Format
MaskFormatter mask = null;
try {
mask = new MaskFormatter("###-####-###");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Formatted TextField
JFormattedTextField fmField = new JFormattedTextField(mask);
fmField.setBounds(125, 87, 90, 20);
add(fmField);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}