Search code examples
javaswingalignmentjdatechooser

Jdatechooser text alignement to RIGHT


I need to align the text in Jdatechooser text field. It always aligns the text(the selected date) to LEFT but i need at RIGHT side.

I have tried this but its not working,

StartJCal.setAlignmentX(RIGHT_ALIGNMENT);

The setTextAlignment method is not available for Jdatechooser.

    StartJCal = new JDateChooser();
    StartJCal.setDateFormatString("yyyyMMdd");
    StartJCal.setFont(new Font("Dialog", Font.PLAIN, 11));
    StartJCal.setSize(new Dimension(105, 0));

This is the piece of code am using.How can i align the text please help


Solution

  • StartJCal = new JDateChooser();
    JTextFieldDateEditor dateEditor = (JTextFieldDateEditor)StartJCal.getComponent(1);
    dateEditor.setHorizontalAlignment(JTextField.RIGHT);
    StartJCal.setDateFormatString("yyyyMMdd");
    StartJCal.setFont(new Font("Dialog", Font.PLAIN, 11));
    StartJCal.setSize(new Dimension(105, 0));
    

    try this. it will solve your problem