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.
Related
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;
});
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.
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);
I am using JavaFX 8u60. I want to give my users the chance to edit a CSS file for a pane in my program, without using an external editor.
For example, the user clicks on a Label, and a dialog to select the color is shown. After the user selects the color, the color is actually written in the CSS file, in the appropriate line...
Are there CSS parsers for JavaFX?
I can't show you any Java code because I'm not sure this can be done.
.table-view .column-header .label{
-fx-font: 18 GatwickSans;
-fx-text-fill: red; //<--- user shall be able to edit this line from my program
-fx-alignment: TOP_LEFT;
}
edit: to clarify, I want to be able to edit a FX-CSS file from Java.
You can use color picker, Try this example
Hbox layout =new HBox(10);
ColorPicker colorPicker = new ColorPicker();
colorPicker.setValue(Color.RED);//Red is the default shown at first
Label label =new Label("Your Text");
layout.getChildren().addAll(label,colorPicker);
//Then
colorPicker.setOnAction(event->{
label.setFill(colorPicker.getValue());
});
Also for css
colorPicker.setOnAction(event->{
label.setStyle("-fx-text-fill: "+colorPicker.getValue()+";");
});
I have used CSSParser:
http://sourceforge.net/projects/cssparser/
It's sufficiently generic and it works a bit like the DOM XML parser. It reads the CSS file and maps it in memory, allowing you to read the single selectors, properties and values, and edit them. Check the discussion on Sourceforge to have some examples, since it lacks documentation.
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.