mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.13k stars 234 forks source link

WebDateField fixed width ? #580

Closed mokun closed 4 years ago

mokun commented 4 years ago

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.

mgarin commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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