Search code examples
javaswingdateformatjformattedtextfield

How to setText() into not enabled JFormattedTextField


I've got problem trying to setText into my JFormattedTextField when it is not enabled. It's all right, when it is... String value is not empty, but the field stays empty.

private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy") {
    @Override
    public Date parse(String source) throws ParseException {
        return (source != null && !source.trim().equals("") && !source.trim().equals(".  .")) ? super.parse(source) : null;
    }
};


  ...
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
`enter code here`...
    jFormattedTextField1.setFormatterFactory(new DefaultFormatterFactory(mf));
            jFormattedTextField2.setFormatterFactory(new DefaultFormatterFactory(mf));
            jFormattedTextField1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    super.mouseClicked(e);
                    showPopup(jFormattedTextField1);
                }
            });
        `jFormattedTextField1.setText("22.10.2012");`

Solution

  • The prolem was with Look and Feel Nimbus. The colour of text and TextField is the same