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

WebDateField fixed width ? #580

Closed
mokun opened this issue Nov 6, 2019 · 4 comments
Closed

WebDateField fixed width ? #580

mokun opened this issue Nov 6, 2019 · 4 comments

Comments

@mokun
Copy link

mokun commented Nov 6, 2019

Hi,

How do I reduce the width of the WebDateField ?

It doesn't adjust dynamically.

Currently it's too wide for my app.

See below the extra whitespace that I circle with a red oval :

webdatefield

How do I manually adjust it ?

I've tried setSize(100, 30): but it can't change the width.

@mokun mokun changed the title WebDateField WebDateField fixed width ? Nov 6, 2019
@mgarin mgarin self-assigned this Nov 6, 2019
@mgarin mgarin added the question label Nov 6, 2019
@mgarin
Copy link
Owner

mgarin commented Nov 6, 2019

Resulting size of the field is either determined by it's preferred size (which usually makes sure that all information in the component is visible - text in the field in this case) or by it's container's layout.

Looking at the screenshot - I'd guess that layout decides the field size in you case, so changing it's size will have no effect because size (and bounds which include size & location) only apply to containers with null layout.

Changing field's preferred size might have effect, but it will depend on how your field's container layout distributes remaining space between it's components. In this particular I doubt it would have any effect either (except for maybe height of the field) because field is stretched by the layout already, meaning it ignores it's current smaller preferred size.

There might also be some issues with field size calculation in theory, but I'm not seeing that happen on any demos I have, so I can't really help any further without knowing the code of the field and container you're using.

@mokun
Copy link
Author

mokun commented Nov 7, 2019

Yes. The preferred size works. I use setPreferredWidth() since I don't need to override its heigfht. Thanks !

Q: how do I override the font and color of the textfield inside ?

The setForeground() and setFont() below don't work :

Date date = new Date(earthClock.getInstant().toEpochMilli()));
WebDateField dateField = new WebDateField(date);
dateField.setPreferredWidth(190);
dateField.setFont(font);
dateField.setForeground(Color.BLUE);

mgarin added a commit that referenced this issue Nov 8, 2019
- WebDateFieldUI.java - Basic Swing methods `setFont`, `setBackground` and `setForeground` are now forwarded from `WebDateField` to it's text field
mgarin added a commit that referenced this issue Nov 8, 2019
- WebDateFieldUI.java - Added a better calculation of potential preferred field size
@mgarin
Copy link
Owner

mgarin commented Nov 8, 2019

Q: how do I override the font and color of the textfield inside ?

It's not possible in the latest released version, but I've added a small improvement that will forward Font and foreground Color provided into WebDateField to the field. It will soon be available in snapshot build of v1.2.11.


Also, regarding the field length - I actually know why it becomes so lengthy now. It adjusts it's columns according to your date pattern. It's not the best solution because it makes fields really long in some cases.

I've added some internal improvements for that, you might not need the custom preferred width anymore on newer version, for instance this is the new preferred size for your pattern:

image

A few extra pixels are added to ensure text will fit in most cases, otherwise it stays really close to actual text width now.

@mgarin mgarin added this to the v1.2.11 milestone Nov 8, 2019
@mgarin mgarin added the question label Nov 8, 2019
@mgarin
Copy link
Owner

mgarin commented Nov 8, 2019

All the problems should be resolved with the next update, so i'll close this issue for now.

@mgarin mgarin closed this as completed Nov 8, 2019
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