How to add calendar in lwuit TextField or comboBox

2.5k views Asked by At

I am creating an application using lwuit. And i want to add calendar in comboBox. please give me an idea as soon as possible..

1

There are 1 answers

0
Mital Pritmani On

Do u mean that you want to add the selected date of calendar component at the end of combobox values or to show the selected date in textbox? If so, then below code shows the selected date of calendar component in textbox:

Button cal = new Button("Calendar");  // button for calendar
cal.addActionListener(new ActionListener() {  // define action for button

                //  action listener to show the calendar container
                public void actionPerformed(ActionEvent ae) {
                    final Form calFrame = new Form();
                    final Calendar cal = new Calendar();
                    calFrame.setScrollable(true);
                    calFrame.setSmoothScrolling(true);
                    calFrame.setIsScrollVisible(true);
                    cal.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent ae) {
                            txtDate.setText(cal.getDate());  // textfield in which date should be set
                            mainForm.showBack();  // main form to show back after calender disappears
                        }
                    });

                    calFrame.addComponent(cal);
                    calFrame.show();
                }
});
            mainForm.addComponent(calButton); // add calendar button to main form

this code will add one calendar button to your main form and will display the selected date in textfield (here named txtDate). If you want to add date in combo values, you can add the selected date in the vector or list of the combo component's vector. If this is not what you want, kindly briefly explain what you want actually to do.