Have one node ignore a CSS class entry - java

So I have the following code snipet which I want applied to 99% of my labels in my JavaFX application. However, sometimes I don't want it applied. Unfortunately whenever I try to call
myFont.setFont(Font.loadFont(etc etc);
It is unable to override the label class in the CSS file. How can this be done? Thank you!
.label
{
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Semibold";
}

There are different ways to do it. Few of the approaches are described here :
Define a different style-class instead of using the default .label and use it on your 99% of labels.
Code :
mylabel.getStyleClass().add("my-label")
CSS :
.my-label {
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Semibold";
}
Remove the default label style class and set a new style class to 1% of the labels. This will remove the already present .label style class from the node. This seems to be an easier approach but if I were you, I would not go with this approach since we <3 the default styles and we want them to be applied to the respective nodes by default.
Code :
mylabel.getStyleClass().setAll("my-label");

.label is one of the built in styles that is applied to all Nodes of type Label. You can remove any style class like this:
Label lbl = ...
lbl.getStyleClass().remove("label");
However I would suggest another approach that does not involve removing a style class especially one of the built ins.
As there seems to be only a selected few labels, that don't have that style you can override it on those Labels:
.label-override {
-fx-font-size: 10pt;
-fx-font-family: "Segoe UI Semibold";
}
Label otherLbl = ...
otherLabel.getStyleClass().add("label-override);

Related

CSS styling of ControlsFX segmented bar text

How can I change the size and color of the text for the ControlsFX segmented bar? The usual way:
-fx-font-size: 15px
Doesn’t seem to work.
It doesn’t matter to me whether I change this using a CSS stylesheet or through the code. I have tried both. -fx-background-color: does work, so my styling is having an effect.
I just can’t seem to find anywhere, or intuitively figure out the correct CSS for how to style the text of the segmented bar control.
Thanks!
ControlsFX uses a default SegmentViewFactory that uses a class called SegmentView with a style class segment-view, so this is the way to style a text in a SegmentedBar:
.segment-view {
-fx-font-size: 15px;
}
Another way to style the text in a SegmentedBar is to use a custom SegmentViewFactory. Here is an example:
SegmentedBar<Segment> bar = new SegmentedBar<>();
bar.getSegments().addAll(
new Segment(2.46, "Apple"),
new Segment(2.43, "Microsoft"),
new Segment(1.94, "Alphabet"),
new Segment(1.72, "Amazon"));
bar.setOrientation(Orientation.HORIZONTAL);
bar.setSegmentViewFactory(segment -> {
Label viewNode = new Label(String.format("%s (%.2fT)", segment.getText(), segment.getValue()));
viewNode.setStyle("-fx-font-size: 15px; -fx-font-style: italic;");
return viewNode;
});

Hover style of a JavaFX MenuItem programatically

I want to know if there is a way to set the hover style of a JavaFX ManuItem without add a stylesheet.
for Node I normally use: this.setOnMouseEntered(e -> this.setStyle(initialStateCss + hoverStateCss));and this.setOnMouseExited(e -> this.setStyle(initialStateCss));
But for MenuItem this events are not available. Someone have an idea of how to do it?
Thanks in advance!
I suggest you to use CSS stylesheets then use the .menu-item:focused selector event. In your CSS file, the markup would look like this:
.menu .menu-item:focused {
-fx-background-color: #FFF6;
-fx-background-radius: 5.0;
-fx-font-weight: bold;
}
I would recommend you to use as little Java style as possible and use CSS stylesheets instead. It would enhance your code as it will be more maintainable.
For more details, this SO request gives useful information about MenuItem's CSS style.

How to style JFXtras CalendarTimeTextField?

I want to style the font of the CalendarTimeTextField Popup control using a CSS File.
The following entry doesn't work for me:
.CalendarTimeTextFieldSkin_popup {
-fx-text-fill: white;
-fx-font-style: italic;
}
Setting the font-type works, changing text color doesn't.
Thanks for supporting me
GGK
The text is rendered with a Text node (https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#text) so use -fx-fill and/or -fx-stroke.

How to set the width of all the tool-tips in SmartGWT applicaion globally?

I have lots of tool-tips in my SmartGWT application and now I want to change the width of each tool-tip without setting width of each individual tool-tip that is most tedious task.
I can set the width of tool-tip in SmartGWT using Canvas#setHoverWidth() but my concern is to apply this setting globally applicable for whole application.
Is there any way in SmartGWT to specify the tool-tip width globally applicable for whole application using CSS or JAVA code?
For sample code have a look at Hovers Tooltips Sample (Smart GWT).
Thanks in advance.
Finally I got the style name that is applied on all the tool-tips.
SmartGWT have a concept of Skinning that is the process of modifying Smart GWT's default look and feel to match the desired look and feel for your application.
A "skin" consists of:
a single CSS stylesheet containing all CSS styles used by Smart GWT components (skin_styles.css)
a single JavaScript file that sets component defaults (load_skin.js)
a directory tree of images organized by component
I found the style canvasHover in skin_styles.css that is used for hovering on Canvas.
I just added min-width: 135px; that changed the width of all the tool-tips globally in the application. By default it's 100px.
/* hover canvas */
.canvasHover,.gridHover,.formHover {
background-color: #fdfdd3;
border: 1px solid gray;
color: black;
font-family: Arial, Verdana, sans-serif;
font-size: 11px;
padding: 5px;
min-width: 135px;
}
Thanks a lot for your attention.
I have no idea about SmartGWT works, but for this kind of dirty things if those elements are attached to the DOM, I'd use GQuery.
Something like:
GQuery.$("#yourTooltipId or .yourTooltipClass", RootPanel.get()).each(new Function() { public void f(Element e){
GQuery.$(e).width(30);
}});
Instead of RootPanel.get(), you can use other scope if for any reason you have all the tool-tips under the same view.

How to add CSS inline in Vaadin?

Is it possible to add inline CSS code programmatically?
Like, I have defined a CSS separator like this:
.hr{
border-top: 1px solid black;
padding-bottom: 10px;
}
Now I sometimes want to have it in a different color or a different size.
Would I have to create further .hr-black, .hr-blue css styles and apply them separately by .addStyleName()? Or can I somehow set the color programmatically?
No, you can only change CSS at specific component using component.addStyleName(), but you can use it dynamically, like this:
if (condition)
component.addStyleName("black");
else
component.addStyleName("blue")

Categories