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
}

Start a new topic
Add Reply




MultiQuote
| 


