Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT Date picker in Java Swing
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas pandey
Date picker in Java Swing
4 Answer(s)      2 years and 5 months ago
Posted in : Swing AWT


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 .


Advertisement
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
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
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 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
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
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
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 Date... a date which is then shown inside the cell and also modified in the backing object
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 Script Code of Calendar and Date Picker or Popup Calendar
Java Script Code of Calendar and Date Picker or Popup Calendar...; This is detailed java script code that can use for Calendar or date picker or popup... selected date from the date picker.  2: calendar.js: Java script code file
iPhone Date Picker
iPhone Date Picker In this tutorial will learn how to use iPhone Date Picker... to show the date which you select on the iPhone date picker with time. The Date... and to check the attributes for the Date Picker select the Date Picker and then click
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
JavaScript calendar date picker
{ } /* the table (within the div) that holds the date picker calendar */ .dpTable { font... picker We are going to discus about JavaScript calendar date picker. We have used basic JavaScript date picker functionality. We use drop-down calendar
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
Date - Swing AWT
Date   sir i have one JSpinner and a textfield that will display the current month and year next to that there is another a Textfield for Date... date,year,month should not be less than current. 2.i want to store these date
Date and Time - Swing AWT
Date and Time  the following program is developed in swings ..... the main objective of this program is to 1> get a date from user 2> retrieve the current date from the system 3> hence find out the difference
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
java swing
java swing  view the book details using swing
Java swing
Java swing  Does Swing contains any heavy weight component
Java swing
Java swing  what are the root classes of all classes in swing
Advertisements
 

 

 

DMCA.com