Date picker in Java Swing

Date picker in Java Swing

Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly give me the code as i am in need of it badly in my live project.

I took ur tutorial to make Date picker in swing .

View Answers

June 25, 2012 at 4:11 PM

Please visit the following link:

Java Date Time Picker Example


June 25, 2012 at 4:22 PM

Hello Sir, Thank you So much for such quick response.I studied the content of the given tutorial thoroughly .

But Sir, I want Time Picker In java swing desktop application. In time picker we can select hours ,minutes ,seconds ,AM ,pm from the popup menu just like that of date tutorial given .

Plz sir send me the code . thanks in advance.


July 2, 2012 at 5:52 PM

import java.awt.*; import java.awt.event.*; import javax.swing.*;

class DatePicker { 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; JButton[] button = new JButton[49];

public DatePicker(JFrame parent) {
    d = new JDialog();
    d.setModal(true);
    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();
        button[x].setFocusPainted(false);
        button[x].setBackground(Color.white);
        if (x > 6)
            button[x].addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    day = button[selection].getActionCommand();
                    d.dispose();
                }
            });
        if (x < 7) {
            button[x].setText(header[x]);
            button[x].setForeground(Color.red);
        }
        p1.add(button[x]);
    }
    JPanel p2 = new JPanel(new GridLayout(1, 3));
    JButton previous = new JButton("<< Previous");
    previous.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            month--;
            displayDate();
        }
    });
    p2.add(previous);
    p2.add(l);
    JButton next = new JButton("Next >>");
    next.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            month++;
            displayDate();
        }
    });
    p2.add(next);
    d.add(p1, BorderLayout.CENTER);
    d.add(p2, BorderLayout.SOUTH);
    d.pack();
    d.setLocationRelativeTo(parent);
    displayDate();
    d.setVisible(true);
}

public void displayDate() {
    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();
    cal.set(year, month, 1);
    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);
    l.setText(sdf.format(cal.getTime()));
    d.setTitle("Date Picker");
}

public String setPickedDate() {
    if (day.equals(""))
        return day;
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
            "dd-MM-yyyy");
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(year, month, Integer.parseInt(day));
    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("popup"); JPanel p = new JPanel(); p.add(label); p.add(text); p.add(b); final JFrame f = new JFrame(); f.getContentPane().add(p); f.pack(); f.setVisible(true); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { text.setText(new DatePicker(f).setPickedDate()); } }); } }


July 2, 2012 at 6:02 PM

Hello Sir, Thanx for ur valuable codes in datepicker in java swing. But what I needed is Time picker in java swing from which i can select Hours,Minutes,seconds,AM,Pm from the Time picker .

Plz give me code for time picker in java swing.

Thanx in advance,

vikas pandey









Related Tutorials/Questions & Answers:
Date picker in Java Swing
Date picker in Java Swing  Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly... tutorial to make Date picker in swing .   Please visit the following
date picker - Java Beginners
date picker  sir i need code for date picker in java swing because for Embedding in my project plz sir
Advertisements
date picker componnt - Java Beginners
date picker componnt  sir i need code for date picker in java swing for my project sir please send me sir
want a program for date picker by using java swings
a look at the following link: Date Picker in java swing...want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing
Date Picker
Date Picker   Hi Java Developers ! I came across the coding for date... in the calendar( by using date picker ) it needs to get updated/highlighted... this for Flight reservation. Should use Java Swing and Database only for this and not any
How to make Time picker in Java Swing
How to make Time picker in Java Swing  Hello Sir, Thank u so much for such a quick reply . I followed date picker tutorial and completed. but sir i want time picker just like date picker in which we can select hours
How to make Time picker in Java Swing
How to make Time picker in Java Swing  Hello Sir, Thank u so much for such a quick reply . I followed date picker tutorial and completed. but sir i want time picker just like date picker in which we can select hours
Java Swing DatePicker
Java Swing DatePicker In this section, you will learn how to display date picker using java swing. The date picker lets the user select the Date through... the Calendar and select a date. It contains an editable date picker, a date field
Date Picker
Date Picker  "I want to set default calendar date when using datepicker. This date means auto-loaded date when the calendar appears. The default date is the current date. I want to change it. How could I do
date picker
date picker  where i have to kept javascript ,css files and images in eclipse... please tell me the location
date time picker
date time picker  I have enetered a date time picker in my jsp file. there is text field before the date time picker. What should i do so... the date time picker gets opened
Date limit on Dojo Date picker - Date Calendar
picker in my project. When user click on date text box, date picker will pop up... want to Date limit for date picker i.e. If i given date limit from 31/03/2008... this validation by getting value from date picker text box or server side also, but I
javascript date picker - Date Calendar
javascript date picker  how to insert a date picker user control in a html/jsp using javascript??? please help, it's urgent.  Hi Friend, Please visit the following links: http://www.roseindia.net/javascript
How to use Date Picker iPhone
How to use Date Picker iPhone  Hi, I am beginner in mobile Application platform. I want to develop a small application in iphone platform to Show current date and display alert view message. So, how to define the date picker
Dyanmically Adding Rows with Date Picker
Dyanmically Adding Rows with Date Picker  Hi Sir, I am doing a project in that i need to add rows dynamically with date picker inside row, send me code as soon as possible. Regards, Santhosh
get date picker values to a textbox
get date picker values to a textbox  I am using DatePicker to select date in a form in asp.net using c#. I need the picked data to get in to a textbox. Please help me soon
jquery date picker
jquery date picker  how can i compare the dates on click from a calendar with the dates that are stored in database
JSF Date picker error - Java Server Faces Questions
JSF Date picker error  hi friend thanks for your reply.i tried it already those codes. But those are not working .i don't know what is the error on my code.here i have placed my code. Please kindly send me
JTable with Date Picker
JTable with Date Picker  Hi, I'd like to implement the following but I have no idea where to start: I have a JTable with 1 column containing... the user to select a date which is then shown inside the cell and also modified
jquery date picker
jquery date picker  I am developing a business calendar.i used the Jquery datepicker plugin.I just now want to get the dates from the the calendar and should get the alert message soon after i click on the particular date.The
Maven dependency for org.webjars.bowergithub.vaadin - vaadin-date-picker version 3.2.0-alpha4 is released. Learn to use vaadin-date-picker version 3.2.0-alpha4 in Maven based Java projects
- vaadin-date-picker version 3.2.0-alpha4 in Java projects. Follow the step by step... 3.2.0-alpha4 of vaadin-date-picker released The developers of   org.webjars.bowergithub.vaadin - vaadin-date-picker project have released the latest
Set Date limit for dojo date picker dynamically - Date Calendar
Set Date limit for dojo date picker dynamically  Hi all, I am using Dojo's date picker in my project. I am trying to set min & max value for disable dates from date picker. There are two fields which are using this date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 2.2.4 is released. Learn to use vaadin-date-picker-flow version 2.2.4 in Maven based Java projects
to use  com.vaadin - vaadin-date-picker-flow version 2.2.4 in Java projects... and includes  com.vaadin - vaadin-date-picker-flow version 2.2.4 java library in your...-picker-flow released The developers of   com.vaadin - vaadin-date-picker
Maven dependency for com.vaadin - vaadin-date-picker-flow version 2.2.5 is released. Learn to use vaadin-date-picker-flow version 2.2.5 in Maven based Java projects
to use  com.vaadin - vaadin-date-picker-flow version 2.2.5 in Java projects... and includes  com.vaadin - vaadin-date-picker-flow version 2.2.5 java library in your...-picker-flow released The developers of   com.vaadin - vaadin-date-picker
Maven dependency for com.vaadin - vaadin-date-picker-flow version 2.2.6 is released. Learn to use vaadin-date-picker-flow version 2.2.6 in Maven based Java projects
to use  com.vaadin - vaadin-date-picker-flow version 2.2.6 in Java projects... and includes  com.vaadin - vaadin-date-picker-flow version 2.2.6 java library in your...-picker-flow released The developers of   com.vaadin - vaadin-date-picker
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.0 is released. Learn to use vaadin-date-picker-flow version 14.5.0 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.0 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.0 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.1 is released. Learn to use vaadin-date-picker-flow version 14.5.1 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.1 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.1 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.2 is released. Learn to use vaadin-date-picker-flow version 14.5.2 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.2 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.2 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.3 is released. Learn to use vaadin-date-picker-flow version 14.5.3 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.3 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.3 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.4 is released. Learn to use vaadin-date-picker-flow version 14.5.4 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.4 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.4 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.5.5 is released. Learn to use vaadin-date-picker-flow version 14.5.5 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.5.5 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.5.5 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.6.0 is released. Learn to use vaadin-date-picker-flow version 14.6.0 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.6.0 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.6.0 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.6.1 is released. Learn to use vaadin-date-picker-flow version 14.6.1 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.6.1 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.6.1 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.6.2 is released. Learn to use vaadin-date-picker-flow version 14.6.2 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.6.2 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.6.2 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 14.6.3 is released. Learn to use vaadin-date-picker-flow version 14.6.3 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 14.6.3 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 14.6.3 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 18.0.4 is released. Learn to use vaadin-date-picker-flow version 18.0.4 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 18.0.4 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 18.0.4 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 18.0.5 is released. Learn to use vaadin-date-picker-flow version 18.0.5 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 18.0.5 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 18.0.5 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 18.0.6 is released. Learn to use vaadin-date-picker-flow version 18.0.6 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 18.0.6 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 18.0.6 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 18.0.7 is released. Learn to use vaadin-date-picker-flow version 18.0.7 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 18.0.7 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 18.0.7 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.0 is released. Learn to use vaadin-date-picker-flow version 19.0.0 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.0 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.0 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.1 is released. Learn to use vaadin-date-picker-flow version 19.0.1 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.1 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.1 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.2 is released. Learn to use vaadin-date-picker-flow version 19.0.2 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.2 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.2 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.3 is released. Learn to use vaadin-date-picker-flow version 19.0.3 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.3 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.3 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.4 is released. Learn to use vaadin-date-picker-flow version 19.0.4 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.4 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.4 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.5 is released. Learn to use vaadin-date-picker-flow version 19.0.5 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.5 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.5 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.6 is released. Learn to use vaadin-date-picker-flow version 19.0.6 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.6 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.6 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.7 is released. Learn to use vaadin-date-picker-flow version 19.0.7 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.7 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.7 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.8 is released. Learn to use vaadin-date-picker-flow version 19.0.8 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.8 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.8 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 19.0.9 is released. Learn to use vaadin-date-picker-flow version 19.0.9 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 19.0.9 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 19.0.9 java library...-picker-flow released The developers of   com.vaadin - vaadin-date
Maven dependency for com.vaadin - vaadin-date-picker-flow version 20.0.0 is released. Learn to use vaadin-date-picker-flow version 20.0.0 in Maven based Java projects
? Steps to use  com.vaadin - vaadin-date-picker-flow version 20.0.0 in Java... and includes  com.vaadin - vaadin-date-picker-flow version 20.0.0 java library...-picker-flow released The developers of   com.vaadin - vaadin-date

Ads