in Vaadin 23 there exists the Lumo compact theme. In the examples/documentation https://vaadin.com/docs/latest/styling/lumo/variants/compact it's shown how to activate this in the main layout via some JS includes.
@JsModule("@vaadin/vaadin-lumo-styles/presets/compact.js")
public class Foo {
}
But unfortunally this happens for all user, and we are not able to provide the users to choose between compact and regular mode.
Compact mode would be great when working on small laptop screens and the regular one for large desktop displays.
Any ideas on how to switch from iside the java code?
You could copy-paste the custom property definitions from the compact mode style sheet into your theme, under a specific selector, which you can then toggle from your Java code.
For example:
frontend/themes/mytheme/styles.css: