2013-09-06 1 views
-2

Я пытаюсь использовать JDateChooser в своем JFrame (код не в beans IDE). Как я могу создать класс JDateChooser и добавить его в JFrame.Невозможно добавить компонент JDateChooser в JFrame

import com.toedter.calendar.JDateChooser; 
import com.toedter.calendar.JDateChooserBeanInfo; 
import com.toedter.calendar.JDateChooserCellEditor; 
import javax.swing.*; 
import java.awt.*; 
class main extends JFrame 
{ 
JDateChooser cdate; 

main() 
{ 
cdate = new JDateChooser(); 
add(cdate); 
setSize(400,200); 
setLayout(new FlowLayout()); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
setVisible(true); 
} 
} 
+1

Можете ли вы показать нам, что вы пробовали? – unholysampler

ответ

1
JDateChooser dateChooser = new JDateChooser(); 
dateChooser.setBounds(20, 20, 200, 30); // Modify depending on your preference 
jFrame.getContentPane().add(dateChooser); 

Чтобы получить дату, вы можете DO-

Date date = dateChooser.getDate(); 

Edit: Исходя из comment-

com.toedter.calendar.JDateChooser dateChooser = new com.toedter.calendar.JDateChooser(); 
dateChooser.setDateFormatString("MM/dd/yyyy"); 

Date date = dateChooser.getDate(); 
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
someJLabel.setText(dateFormat.format(date)); 
+0

Я попытался сделать то же самое, но компилятор показывает исключение «noSuchMethod» в runtym ... Я использую файл «com.toedter.calendar.JDateChooser». –

+0

@NaviAulakh См. Мое редактирование. –

+0

он все еще показывает ошибку «nosuch method». –

 Смежные вопросы

  • Нет связанных вопросов^_^