How to add calendar in lwuit TextField or comboBox

假如想象 提交于 2020-01-15 05:46:05

问题


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:


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.



来源:https://stackoverflow.com/questions/6148862/how-to-add-calendar-in-lwuit-textfield-or-combobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!