0

I have a Java app and a JDateChooser. The problem comes when I start my app.

The JDateChooser remains invisible and appears only after I iconify my app.

What I should do?

dateChooser = new JDateChooser();
dateChooser.setDateFormatString("d/MM/yyyy");
dateChooser.setBounds(48, 68, 102, 20);
JTextFieldDateEditor editor = (JTextFieldDateEditor) dateChooser.getDateEditor();
editor.setEditable(false);
frmCodfiscextractor.getContentPane().add(dateChooser);

Also, I put this at the end of the class :

frmCodfiscextractor.repaint();
Zabuzard
  • 25,064
  • 8
  • 58
  • 82
Gabriel
  • 464
  • 4
  • 17
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Apr 22 '18 at 14:53

2 Answers2

1
import java.awt.EventQueue;
import javax.swing.JFrame;
import com.alee.laf.WebLookAndFeel;
import com.toedter.calendar.JDateChooser;
import com.toedter.calendar.JTextFieldDateEditor;

public class demo {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    WebLookAndFeel.install();
                    demo window = new demo();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public demo() {
        initialize();
    }
    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JDateChooser dateChooser = new JDateChooser();
        dateChooser.setDateFormatString("d/MM/yyyy");
        dateChooser.setBounds(74, 193, 181, 30);
        JTextFieldDateEditor editor=(JTextFieldDateEditor)dateChooser.getDateEditor();
        editor.setEditable(false);
        frame.getContentPane().add(dateChooser);
        frame.repaint();
    }
}
md azaz
  • 68
  • 7
0

Use latest version of JCalender. It is correct working in my case.

md azaz
  • 68
  • 7