3

I'm writing a program with a toolbar in the head. The only problem is that I can't set the correct size on the component in my toolbar, namely a datepicker.

screenshot

So I want to resize the datepicker in the toolbar. How can I fix this?

The most beautiful option would be to resize it that the textfield would just be big enough to display the date.

Joël Craenhals
  • 475
  • 7
  • 19

1 Answers1

4

For the toolbar to pickup component size properly you have to set its preferred, maximum and minimum size. Here is what works for me:

Dimension d = cmpt.getPreferredSize();
d.width = YOUR_NEW_WIDTH;
cmpt.setMinimumSize(d);
cmpt.setMaximumSize(d);
toolbar.add(cmpt);
Eugene Ryzhikov
  • 17,131
  • 3
  • 38
  • 60
  • 2
    Try not to forget, the fonts you are designing with may not be the fonts on the users system and that this could come back to bite you. You could also try a different layout manager? – MadProgrammer Jul 14 '12 at 21:21
  • Thank you... But How to Horizontal Resizable? – joseluisbz Jun 01 '17 at 14:53