user3164187
user3164187

Reputation: 1432

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

Upvotes: 1

Views: 1728

Answers (2)

user3699810
user3699810

Reputation: 1

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));

Upvotes: 0

lakshman
lakshman

Reputation: 2741

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

Upvotes: 1

Related Questions