1

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3164187
  • 1,382
  • 3
  • 19
  • 50

2 Answers2

1
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

lakshman
  • 2,641
  • 6
  • 37
  • 63
0

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));
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54