with Vaadin 14(.1.19) comes this Time Picker component: https://vaadin.com/components/vaadin-time-picker/java-examples
This is how it looks like (when it's read-only):
How can I get this Time Picker to show the time centered like this (this is a screenshot of a manual manipulation in the browser (setting text-align:center directly at the embedded input field), not a programmed solution)?
I tried to set the text-align property in the Java code without effect:
TimePicker timepicker = new TimePicker();
timepicker.getElement().getStyle().set("text-align", "center");
And I searched for a theme variant. But that seems to exist for TextFields and derived fields only:
EmailField emailFeld = new EmailField();
emailFeld.addThemeVariants(TextFieldVariant.LUMO_ALIGN_CENTER);
You will need to change the CSS within the shadow DOM of TimePicker's TextField value part, we use theme attribute as additional selector in order to not to theme all the text fields:
[part="value"] {
:host([theme~="center"]) text-align: center;
}
Include the CSS via #CssImport annotation, theming the text field and set the theme attribute to the date picker. The theme attribute is propagated to the text field used in the date picker:
#CssImport(value = "./styles/my-time-picker-styles.css", themeFor = "vaadin-time-picker-text-field")
public class YourViewOrLayout extends Composite<Div> {
...
timePicker.getElement().setAttribute("theme", "center");
}
I explained it in bit more detail in this answer.
Related
Picker has two components :
The Initial/Selected value displayed in Codenameone UI.
The Native picker dialogs/sheets.
It makes sense that we can not control the theme/color/style of Native Pickers as they are influenced by an OS-specific theme selected by the user.
But how do we change the color of text inside the picker in Codenameone Interface?
What I want to do in the following screenshot is to make the texts "3/20/20, 00:00, & 0-5 persons" white.
What I tried :
Channing the "Label" font-family in CSS changed the font so I tried changing the "color" from CSS but it didn't help.
I tried changing the foreground color like this : timePicker.style.fgColor = 0xfffff
In CSS I defined a style.
DropdownStyle{
background-color: #333333;
color: #FFFFFF;
}
Then I set the style to picker
datePicker.uiid ="DropdownStyle"
But none of the above ways worked as expected.
What is the right way to do it? I believe I am missing a very simple thing but I couldn't find it myself.
AS #shai-almog suggested, after digging through Component Inspector, I found out that
A PickerComponent has the ID "TextComponent" so if we replace the UIID of PickerComponent it's going to change the style of just the Holder Component that's why I was able to change the background-color only but not the text.
Inside it, there is Picker which Represents the Text and has the id TextComponentField.
So I had to Style them individually like this :
TextComponent{
background-color: rgba(0, 0, 0, 0.0);
}
TextComponentField{
color: white;
}
Output :
Im using codename one 3.5.8 and need to add a checkbox to a multibutton(as the example https://www.codenameone.com/javadoc/com/codename1/components/MultiButton.html) but when adding it to my code ,it seems as though it is being ignored, the checkbox is not adde to my multibutton, this behavior happens on the emulator and also on my test device(android 6.0). is there anything that needs to be apllied additional to setCheckBox(true)
img2:
img3:
In case somebody is having this same behavior, the problem is because in some themes, the checkbox images make the checkbox invisible,the solution is to delete(or replace) the checkbox related images in the constant tab(on theme editor) like explained here:
CodenameOne - change color of checkbox in theme
The MultiButton itself should become a checkbox and would be rendered based on API conventions. You might need a revalidate() if the button is already showing in the UI.
Form hi = new Form("Multibutton", BoxLayout.y());
MultiButton component = new MultiButton();
component.setTextLine1("Name");
component.setTextLine2("Numero de reservacion:");
component.setTextLine3("Fecha de reservacion:");
component.setTextLine4("Estado:");
component.setCheckBox(true);
hi.addComponent(component);
hi.show();
I have two labels, two datepickers, and a submit button within a DockLayoutPanel. I'm trying to just get the button to show up in the center of the panel.
Here is the code I am trying to get just to get the button centered:
Button b = new Button("Submit", new ClickListener()
{
public void onClick(Widget sender)
{
getAwards(text.getText(),text2.getText());
}
});
b.setWidth("80px");
b.addStyleName("gwt-Button");
and within my css:
.gwt-Button{
margin-left:auto;
margin-right:auto;
}
What edits or method do I have to take to actually get this to work?
Edit: For extra information, this button is being added to a DockLayoutPanel
Try:
.gwt-Button{
position:absolute;
left:50%;
margin-left: -40px; /* Width Button /2 */
}
Try disabling the loading of whatever default GWT theme you are using (such as clean) in your gwt.xml file, it may be messing with things, since you're using the same class name.
Alternatively, just use a CSS class name other than "gwt-Button" here.
Why can't I apply custom css styles to a single TextBox?
I'm trying to set some error styles on a single TextBox. What's wrong with the following implementation?
init:
static final String STYLES = ErrorRes.INSTANCE.css().style();
#UiField TextBox box;
box.setStylePrimaryName(STYLES);
Resource interface
interface ErrorRes extends ClientBundle {
static final ErrorRes INSTANCE = GWT.create(ErrorRes.class);
#Source("Error.css")
Style css();
interface Style extends CssResource {
#ClassName("gwt-TextBox-error")
String style();
}
}
Error.css
.gwt-TextBox-error {
border: 1px solid red !important;
}
If you whant to get gwt-TextBox-error style name on widget, you need set box.setStylePrimaryName("gwt-TextBox"); - it's by default. And when error occured use box.setStyleDependentName("error", true); HTML will be class="gwt-TextBox gwt-TextBox-error".
And to clear error style, use box.setStyleDependentName("error", false);
OR
You can use addStyleName("gwt-TextBox-error") and removeStyleName("gwt-TextBox-error") in a same way.
---UPDATE---
So, I tryed to run your case and it works well. At the first of all you need inject css from resources to page in runtime:
ErrorRes.INSTANCE.css().ensureInjected();
I use it in the begining of onModuleLoad()
Then, to add error style use: box.addStyleName(STYLES);
and box.removeStyleName(STYLES); to remove it.
You can't use pair setStylePrimaryName() and setStyleDependentName() with bundled css becouse css name will be obfuscated.
How to change single element of the widget style in GWT. I would like to create new version of TextBox style, so that only the border color changed to red, for example.How to get to the style responsible for the TextBox?
I tried to create new style
.gwt-TextBox.invalid {
border-color: red;
}
but it does not work.
Make sure you add class invalid to your TextBox:
textBox.addStyleName("invalid");
Use CssResource to associate your CSS file with GWT: http://code.google.com/webtoolkit/doc/latest/DevGuideUiCss.html#cssfiles