Date picker in Java Swing

Ads
 

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
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
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
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
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
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  view the book details using swing
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: http://www.roseindia.net/java/example/java/swing/ Thanks
java swing.
java swing.  Hi How SetBounds is used in java programs.The values in the setBounds refer to what? ie for example setBounds(30,30,30,30) and in that the four 30's refer to what
JAVA SWING
JAVA SWING  Hi.... Iam doing project in java...and my front end in swing ..our project is like billing software... then what are the topics i want cover? then how to design? pls help me
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
Java Date
Java Date  Hi, What is the API for Date management in Java? How use the Java Date API for manipulating date object in Java? Provide some... of API for working with date and time objects in Java. You can also use third
Java swing
Java swing  how to create simple addition program using java swing?   import java.awt.*; import javax.swing.*; import java.awt.event.*; class SumOfNumbers extends JFrame { SumOfNumbers(){ JLabel lab1=new
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code for the above item   import java.sql.*; import java.awt.*; import javax.swing.
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form on jinternalframe and connect to mysql. import java.io.*; import java.sql.*; import java.awt.
Java swing
Java swing  How to combine two java files
java swing
java swing  meaning of out.flush
Java Swing
Java Swing  I want scroll bar in a frame is it possible? if it is possible means i want coding for that please send me a reply

Ads