Question

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

Was it helpful?

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

OTHER TIPS

Similar but not passing through getComponent()

StartJCal = new JDateChooser();

JTextFieldDateEditor dateEditor = (JTextFieldDateEditor)StartJCal.getDateEditor();
dateEditor.setHorizontalAlignment(JTextField.RIGHT);

StartJCal.setDateFormatString("yyyyMMdd");
StartJCal.setFont(new Font("Dialog", Font.PLAIN, 11));
StartJCal.setSize(new Dimension(105, 0));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top