Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Set the default minimum size of date picker and time picker text field, based on current component settings. Allow programmer overrides of the horizontal and vertical size settings. #13

Closed
BlakeTNC opened this issue Apr 18, 2016 · 7 comments

Comments

@BlakeTNC
Copy link
Contributor

BlakeTNC commented Apr 18, 2016

Set minimum size of date picker and time picker text field, based on the font metrics of the current display font, and the longest standard time string that would be output by the current display format.

This calculated minimum size should be the default. However, the programmer should be able to override this behavior to set their own minimum size if desired.

@BlakeTNC BlakeTNC changed the title Feature request: Set minimum size of date picker and time picker text field, based on current component settings. Feature request: Set default minimum size of date picker and time picker text field, based on current component settings. Apr 18, 2016
@BlakeTNC BlakeTNC changed the title Feature request: Set default minimum size of date picker and time picker text field, based on current component settings. Feature request: Set the default minimum size of date picker and time picker text field, based on current component settings. Apr 18, 2016
@BlakeTNC
Copy link
Contributor Author

BlakeTNC commented May 2, 2016

This section of conversation was moved from the "General Discussion" thread into "Issue 13", on 2may16. This conversation was relocated here because it has significant overlap with this issue. -Blake


Hi Blake, sorry to bother you again,
could you tell me how can I resize the JTextField where the date is inserted?
Whit this new date format I need it smaller, furthermore using the Numbus look and feel the text field of the date picker is a bit higer than a normal JTextField.
If I try to use the methods setMinumumSize, setMaximumSize and setPreferredSize on the datePicker the datePicker is resized but his content is cropped and not resized.
Could you kindly give me an help?
Thanks in advance.
(Gittino)


Hello Gittino, When you say "the content is cropped", are you talking about the text inside the component?

By default, the date picker resizes itself to fit all contained components, including the buttons (which are enlarged by Nimbus), and including the font size chosen by the programmer. If you need a smaller date picker, you can force it to be smaller with the functions that you mentioned, but as you noticed, such forcing will crop the text. You can make the font smaller by choosing any font that you wish as the display font. Here's an example of changing the font:

    // Create a date picker: Custom font.
    dateSettings = new DatePickerSettings();
    dateSettings.fontValidDate = new Font("Monospaced", Font.ITALIC | Font.BOLD, 17);
    dateSettings.colorTextValidDate = new Color(0, 100, 0);
    dateSettings.setInitialDateToToday();
    datePicker = new DatePicker(dateSettings);

The typical choice made by most programmers would be to (optionally) make the date picker bigger, but never to make it smaller than the defaults. If you wish to make it smaller without setting a maximum size or a preferred size, you would choose a normal or relatively small display font and you would probably not choose the Nimbus style for this component. Or else, you might set Nimbus to use smaller buttons as described here: https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/size.html I've never tried this with Nimbus but the Oracle documentations say that it's possible. (Nimbus is the only built-in look and feel that allows you to change your desired sizes.)

warm regards,
Blake


Actually my issue is not relative to the text cropping, I will better explain with two images.

example

On the left there is a normal text field, as you see the font size fits perfectly on it, but the DatePicker's textfield is higher. It is also larger than my needs, inserting a date using the format dd/MM/yyyy there is unused empty space on its right.
You can see on the right of the image an example of what I would like: the font size is always the same and the button has the same size of the datepicker one, but I have defined the size of the textfield to give it the same height than the other fields in the panel and its width to be appropriate for a date in the format of dd/MM/yyyy
So I guess if there is a manner to do such a resizing of the JTextField used by the datepicker.

This is instead an example of what appens when I try to reduce the size of the datePicker.

example2

As you can see the entire button has been cropped out (but there is still wasted space after the text in the textfield) also the bottom border has been cropped but there is still a certain margin between the text and the border of the textfield that could be reduced.
(Gittino)

@BlakeTNC
Copy link
Contributor Author

BlakeTNC commented May 2, 2016

hello Gittino,
I see. Okay, your post describes two issues, extra horizontal space and extra vertical space.

The extra horizontal space after the date is an effect of of a known issue, (#13). What's happening is that the date picker layout currently specifies a minimum size of 125 pixels for the text field (and no maximum size). This size is big enough for most "long versions" of dates on the calendar month with the most characters (in English and other languages) similar to "September 29, 2016". When no minimum size is specified, the text field shrinks down to nothing, which would have been a bigger problem. The current design was basically a "good enough" layout choice to avoid a lot of extra premature coding.

When issue #13 is fixed, the horizontal distance issue will be fixed as well. (Especially if the programmer is allowed to override the minimum size.) Assigning a "customized default" minimum horizontal size will require calculating the dimension from the programmers current date format, locale (language), the month with the greatest number of characters in the current language, the current font(s), and font metrics. This is not the simplest calculation in the world, which is why it was not built in to the library from beginning. However it is still doable. The planned programmer override will also allow for any more specific aesthetic desires.

The extra vertical space is a side effect of the fact that the layout is designed so that the text field will always take up the same height as the button, combined with the situation that you are using Nimbus. As mentioned (by you, and in a previous issue by Taurendil above), Nimbus uses extraordinarily large buttons by default, plus a little extra invisible border around the button. To fix this problem without modifying LGoodDatePicker, you would need to reduce your button's vertical size, which is currently possible. I could also add a feature request to #13 to allow the text field to (optionally) be resized independently of the button. That (feature request) would allow the text field to be made smaller without shrinking the button.

I'm thinking this proposed work is (still) classified as an enhancement rather than a bug. The current layout is working well for most developers, and even in your use case the layout is causing "extra" space rather than "not enough" space, which may not be a aesthetically ideal, but is preferred over the alternative. Still, I will move issue #13 higher on the "mental priority queue" for this library.

warm regards,
Blake

@BlakeTNC BlakeTNC changed the title Feature request: Set the default minimum size of date picker and time picker text field, based on current component settings. Feature request: Set the default minimum size of date picker and time picker text field, based on current component settings. Allow programmer overrides of the horizontal and vertical size settings. May 2, 2016
@BlakeTNC
Copy link
Contributor Author

BlakeTNC commented May 3, 2016

With the release of LGoodDatePicker 5.3.1, this enhancement is now implemented. See the release details for a description of the new features.
-Blake

@BlakeTNC BlakeTNC closed this as completed May 3, 2016
@Git-GT
Copy link

Git-GT commented May 4, 2016

Hi Blake,
thanks a lot for the quick response and the immediate release of a new version that in part solve my issue.
I did a very small change to the component to allow to manually set the datepicker JTextField dimension and made a pull request so maybe you can merge it in the next version.
Feel free to modify my update or discard it if you don't like it.
Best regards

@BlakeTNC
Copy link
Contributor Author

BlakeTNC commented May 4, 2016

Hi Gittino,
As of LGoodDatePicker 5.3.1, the programmer can manually change the dimension of the text field using the function: DatePickerSettings.setSizeTextFieldMinimumWidth(). (Thank you for the effort to fix the issue, but I will be declining the pull request, because it duplicates the above functionality.)

Just so you know, after you upgrade to 5.3.1, you probably would not need to manually change the width because the date picker now has a new default sizing behavior. It dynamically resizes itself to to this date format that is applied (and the locale and font). So with your previously described problem, the date picker would now be the appropriate size for your smaller numeric format.

Let me know if this enhancement works for you.

warm regards,
Blake

@BlakeTNC
Copy link
Contributor Author

BlakeTNC commented May 5, 2016

Hi Gittino,
With the latest release, you will find that the date picker text field and popup menu button are now -public- members of the DatePicker class (instead of the previous protected/package variable status). This should allow you and other programmers to perform many desired customizations on the look and feel of the date picker, that are not supported directly by the DatePickerSettings. This would include changing the height of the text field at will.

With this change, I will now consider all parts of this issue completely fixed, (unless I hear otherwise from you or others). Thank you.
Blake

@Git-GT
Copy link

Git-GT commented May 5, 2016

Hi Blake,
thanks a lot, I really appreciate your willingness and the rapidity with which you solve the reported issues.
Have a nice day.
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants