I am developing a java desktop app. I wanna implement Date of Birth selecting using JCalendar. I have a JLabel and this jCalendar is added to JLabel .And set position using setBounds().But the calendar is overlapping with other components and i can't select the date so what should i do?
Here is my code snippet
JCalendar dob=new JCalendar();
raillabel. add(dob);
dob.setBounds(250, 186, 320, 330);
First off, why are you trying to add
JCalendar
to aJLabel
? You can easily add this to aJPanel
:If you still want to add this
JCalendar
to aJLabel
then you need to provide a LayoutManager to this last one in order to properly add components to it:Take a look to A Visual Guide to Layout Managers.
As @mKorbel says in his comment you shouldn't use
NullLayout
andsetBounds()
method to set the component location/size. This is the task layout managers are intended for.Finally:
You may want to try
JDateChooser
instead, which allows selecting a date or type it by hand:Picture