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

Ads









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 componnt - Java Beginners
date picker componnt  sir i need code for date picker in java swing for my project sir please send me sir
Advertisements
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
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
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
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
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
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
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
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
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 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.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.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.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.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.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.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

Ads