Share on Google+Share on Google+

k murali
1 Answer(s)      7 years ago
Posted in : Date-Calendar
sir,i am do the project on swings,i want a datepicker in java,how to use datepicker in my swings application,plz provide a example for to use the datepicker in application sir,plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz


View Answers

April 16, 2010 at 3:35 PM

Hi Friend,

Try the following code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class DatePicker {
JButton[] button = new JButton[49];
int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
JLabel l = new JLabel("",JLabel.CENTER);
String day = "";
JDialog d;
public DatePicker(JFrame parent) {
d = new JDialog();
String[] header = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
JPanel p1 = new JPanel(new GridLayout(7,7));
p1.setPreferredSize(new Dimension(430,120));
for(int x = 0; x < button.length; x++){
final int selection = x;
button[x] = new JButton();
if(x>6)button[x].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
day = button[selection].getActionCommand();
if(x < 7){
JPanel p2 = new JPanel(new GridLayout(1,3));
JButton previous = new JButton("<< Previous");
previous.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JButton next = new JButton("Next >>");
next.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
public void setDates(){
for(int x = 7; x < button.length; x++) button[x].setText("");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
for(int x = 6+dayOfWeek,day = 1; day <= daysInMonth; x++,day++) button[x].setText(""+day);
d.setTitle("Date Picker");
public String displayDatePicked() {
if(day.equals("")) return day;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
return sdf.format(cal.getTime());
class Picker{
public static void main(String[] args) {
JLabel label = new JLabel("Selected Date:");
final JTextField text = new JTextField(20);
JButton b = new JButton();
ImageIcon icon= new ImageIcon("cal.gif");
JPanel p = new JPanel();
final JFrame f = new JFrame();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
text.setText(new DatePicker(f).displayDatePicked());


Related Tutorials/Questions & Answers:
Hi,  Hi,what is the purpose of hash table
Hi..   what are the keywords available in simple HelloWorld program
Hi..  what are access specifier available in java
Hi,   labels = new Hashtable<Integer,JLabel>
HI.  hi,plz send me the code for me using search button bind the data from data base in dropdownlist
Hi..  null is a keyword.True/False?   hi friend, In Java true, false and null are not a Java keyword they are literals in Java. For reading in detail go through the following link The null keyword
hi....  plzz sent me d code for counting vowels in a string... gui programme
Hi  Hi How to implement I18N concept in struts 1.3? Please reply to me
Hi  Hi this is really good example to beginners who is learning struts2.0 thanks
hi,  print("code sample");how to display all elements in 2d array usin any one loop
Hi   how to read collection obj from jsp to servlet and from jsp - jsp?   Hi Friend, Please visit the following link: Thanks
hi....  a programme which displays a combobox which contains num from 1 to 10 and calculates the factorial of dt num which user clicks
Hi  I want import txt fayl java.please say me...   Hi, Please clarify your problem! Thanks
hi   I have connected mysql with jsp in linux and i have used JDBC connectivity but when i run the program, its not working the program is displaying
hi   'print("code sample");`class example(){ public.static.void.main(); system.out.println("this is first pro");}   class example{ public static void main(String[]args){ System.out.println("this is first pro
Hi..  diff between syntax and signature?   signature is a particular identity of a method in terms of its argument order ,type and their number e.g. void A(arguments) then here the order ,type and number of arguments
Hi  Hi All, I am new to roseindia. I want to learn struts. I do not know anything in struts. What exactly is struts and where do we use it. Please help me. Thanks in advance. Regards, Deepak
hi!  how can i write aprogram in java by using scanner when asking user to enter element user will be free to enter any type that he/she wants to to enter, like(int,double,float,String,....) thanx for answering....   Hi
Hi..  what are the steps mandatory to develop a simple java program?   To develop a Java program following steps must be followed by a Java developer : First of all the JDK (Java Development Kit) must be available
hi   on clicking on button on 1st jsp page i want to display following options like friends,family,doctor etc.on next jsp page and also i want link to those options through which i can save the data from 1st jsp in different
hi   on clicking on button on 1st jsp page i want to display following options like friends,family,doctor etc.on next jsp page and also i want link to those options through which i can save the data from 1st jsp in different
online multiple choice examination  hi i am developing online multiple choice examination for that i want to store questions,four options,correct answer in a xml file using jsp or java?can any one help me?   Please
hi  what is the code for printing stars as follows * * * * * * * * * *print("code sample");   Hi Friend, Try... num=4; int p = num; int q = 0; for (int i = 0; i <= num; i++) { for (int j
hi  int A[]=new int{2,5,4,1,3}; what is the error in declaration of this   Hi Friend, This is the wrong way of declaring an array. Array is always declared in the following ways: 1)int arr[]=new int[5]; 2)int arr
Hi   I need some help I've got my java code and am having difficulty to spot what errors there are is someone able to help import java.util.Scanner; public class Post { public static void main(String[] args) { Scanner sc
hi.......  i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design... for such a programme... plz help me...   Hi Friend, Try this: import java.awt.
hi!  public NewJFrame() { initComponents(); try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin"); } catch(Exception e
Hi   I have got this code but am not totally understanding what the errors. Could someone Please help. Thanks in advance! import java.util.Random; import java.util.Scanner; private static int nextInt() { public class
storing data in xml file using jsp  hi i am storing data in xml file using this when i enter data into xml file i am getting xml declaration for each specified data?can any one help me to prevent this?   <
hi   i want to develop a online bit by bit examination process as part of my project in this i am stuck at how to store multiple choice questions options and correct option for the question.this is the first project i am doing
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> <%@ page contentType="text/html;charset=windows-1252"%> <html> <head> <meta http-equiv
Java Spring Hibernate Struts Training is this programm efficient to find the day of the given date . can it be more normalized ? date program What is License Terms for using your code current date set date date Cannot convert 1/23/13 1:18 PM of type class java.util.Date to class java.sql.Timestamp Dyanmically Adding Rows with Date Picker Dyanmically Adding Rows Calender in JSP Calender in JSP richfaces jsf how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server? Database Countdown timer to show a link Find whether a date will be in the current quarter or the next quarter prudhvi code Buy Flowers Online i want to create dynamic calendar in java i want to create dynamic calendar in java date Addintion in year fields of sql date in a java page storing date from html form to oracle 10g using servlet code can u help me to get a calendar with color codes on days ??? html retrieve value from db in text box + calendar implementation. How to add two calendars on the same html page validationrule for date as format yyyy-mm-dd in drools java program program jquery date picker database mysql want the code for calender in php+htmal page Reading the Date and time values from excel sheet Baloon Popup in GWT project calender event Only Display Date date and time in awt(java) time get date picker values to a textbox conept - Date Calendar How to display current date in textbox - Date Calendar this is my code java - Date Calendar ask how function jCalender - Date Calendar Set Date limit for dojo date picker dynamically - Date Calendar


Advertisement null