School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,149 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,879 people online right now. Registration is fast and FREE... Join Now!



Date Picker

Date Picker Rate Topic: -----

#1 lover2000  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 10
  • Joined: 06-April 09


Dream Kudos: 0

Posted 24 April 2009 - 03:56 AM

Hi,

is there any easy way to create a java bean which will act like a combo box to get the date in dd-mm-yyyy format. I tried to create a bean but I am struggling with it.
package cboDate;

/**
 *
 * @author Kishor
 */
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Date;
import java.util.Calendar;
import javax.swing.JOptionPane;
public class cboDate extends javax.swing.JPanel {

	/** Creates new form cboDate */
	public cboDate() {
		initComponents();
	}
	protected String dd;

	public String getDD() {
		return dd;
	}

	public void setDD(String dd) {
		this.dd = dd;
	}
	protected String mm;

	public String getMM() {
		return mm;
	}

	public void setMM(String mm) {
		this.mm = mm;
	}
	protected String yyyy;

	public String getYYYY() {
		return yyyy;
	}

	public void setYYYY(String yyyy) {
		this.yyyy = yyyy;
	}


	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		cboMM = new javax.swing.JComboBox();
		cboDD = new javax.swing.JComboBox();
		txtYYYY = new javax.swing.JTextField();

		cboMM.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

		cboDD.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
		cboDD.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cboDDActionPerformed(evt);
			}
		});

		txtYYYY.setAlignmentX(0.0F);
		txtYYYY.setAlignmentY(0.0F);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addComponent(cboDD, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addComponent(cboMM, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addComponent(txtYYYY, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
				.addContainerGap())
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGap(11, 11, 11)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(cboDD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(cboMM, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
					.addComponent(txtYYYY, 0, 0, Short.MAX_VALUE)))
		);
	}// </editor-fold>

	private void cboDDActionPerformed(java.awt.event.ActionEvent evt) {									  
		// TODO add your handling code here:

	}									 

  
 protected void paintComponent( Graphics g )
	{
		g.setColor( getForeground() );

	   int h=cboMM.getHeight()+0;
	   int w=cboMM.getWidth();// txtYYYY.getWidth()+10;
	   txtYYYY.setPreferredSize(new Dimension(w, h));
	   Calendar cal=Calendar.getInstance();

	   //int dd=cal.DAY_OF_MONTH;// cal.get(Calendar.DATE);
	   cboDD.setSelectedItem(dd);
	   cboDD.setSelectedItem(this.dd);
	   cboMM.setSelectedItem(this.mm);
	   txtYYYY.setText(this.yyyy);
	   }

	// Variables declaration - do not modify
	private javax.swing.JComboBox cboDD;
	private javax.swing.JComboBox cboMM;
	private javax.swing.JTextField txtYYYY;
	// End of variables declaration

}




Was This Post Helpful? 0
  • +
  • -


#2 g00se  Icon User is online

  • D.I.C Lover
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,751
  • Joined: 19-September 08


Dream Kudos: 0

Posted 25 April 2009 - 05:20 AM

Use JCalendar

http://www.toedter.c...ndar/index.html
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month