In that picture, I want to make "file" "edit" "view" bold. I am new to JavaFX please tell me in detail. I am using scene builder but in that, it is not there. thanks in advance
Using CSS:
.menu-bar .menu .label {
-fx-font-weight: bold;
}
Since you say you're new to JavaFX:
JavaFX CSS Reference Guide
A helpful resource for looking up the CSS structures of various JavaFX Nodes
Scene Builder CSS Properties/Analyzer
Oracle documentation on using Scene Builder's CSS features. Hasn't been, and might never be, updated for JavaFX 9.
While Oracle no longer maintains Scene Builder I believe the documentation should be helpful.
Related
I have a program that can load plugin modules and these plugin modules I don't have much control over (outside of instructing customers about guidelines on how to create their modules).
I'm, however, trying to create some Style Themes (e.g. 'lightTheme' and 'darkTheme') for my application that I'd also like to propagate to any UI elements that may be created in any plugins.
Here's my problem, in one of the plugins I noticed that a bare QWidget (e.g. QWidget *widget = new QWidget(); was created that has no parent and I'm trying to figure out how to style this window.
Qt in this case treats this view kind of like a QDialog, however in the stylesheet I need to use QWidget to style this view (QDialog doesn't do anything). As you might expect adding style to QWidget (e.g. QWidget { background-color: black; } with cause a whole host of other style changes throughout my program that I don't want.
So what I'm looking for is how to "style a QWidget that doesn't have a parent".
I was expecting to do something like:
parent > QWidget { background-color: black; }
But I can't figure out what to put for the 'parent' since I know this widget has no parent.
Any help would be appreciated.
I made a CSS
.button{
-fx-pref-height: 28px;
-fx-pref-width: 100px;
}
and I want to add this particular CSS to all the scenes in my application. How am I suppose to so? Glad for any help.
To be accurate, I have a radio button in one scene and by clicking it I want all the buttons in different scenes present in my application changes according to this CSS.
Put this CSS into an external stylesheet and include it in each scene.
Scene scene = new Scene(new Group(), 500, 400);
scene.getStylesheets().add("path/stylesheet.css");
See the documentation here.
I'm making a GUI in JavaFX Scene Builder and would like all text (Labels, Text Fields, Comboboxes) to use the same font. The problem is it's a custom font that likely won't be on every client's computer.
I've tried CSS:
#font-face {
font-family: DIN;
src: url(DIN.tff);
}
.text {
-fx-font-family: DIN;
-fx-font-style: bold;
}
Saved the above code to file Font.css and tried applying it to each GUI element through Scene Builder's JavaFX CSS fields, but it's not working.
Have I made a mistake in the CSS? Or is there a better way to go about this? I'd prefer not to have to load the font and set it for every element in the Java code itself if I don't have to.
Make sure to use Font.loadFont to actually load the font on application startup. Then you should be able to use the font from CSS. Be careful to use the font's name, not the font file's name. That's a common mistake.
I have used the following before to load and use a custom font:
Font.loadFont(getClass().getResourceAsStream("/resources/fonts/marck.ttf"), 14);
and:
-fx-font-family: "Marck Script";
FYI: the quotes are only needed if the name contains a space.
I'm digging into customizing controls via CSS and I got pretty far. So I'm able to fully customize my scrollbar by e.g. setting track's background to transparent and so on. But I'm stuck with the ScrollBarSkin (investigated via ScenicViewer). It seems that this skin has a default background color (gradient) and a border, which I'm not able to modify.
So my question is, how can i access the e.g. TableCellSkin or ScrollBarSkin, to modify background color and insets via CSS?
edit: I'm using jdk7
edit2: i found some syntax in the caspian.css for the ScrollPaneSkin. I tried the same for the scrollbar and a tablecell with:
ScrollBarSkin>* {
-fx-base: transparent;
-fx-border-color: #00ff00;
-fx-background-color: #0000ff;
}
but with no luck.
found solution based on jewelsea's answer (thx mate!)
I made a new class extending ScrollBarSkin and I'm overriding the getSkinnable(). This looks like this:
public class MyScrollBarSkin extends ScrollBarSkin{
public MyScrollBarSkin(ScrollBar scrollBar) {
super(scrollBar);
}
#Override
public Insets getInsets() {
// TODO Auto-generated method stub
return super.getInsets();
}
#Override
public ScrollBar getSkinnable() {
ScrollBar curr = super.getSkinnable();
curr.getSkin().getNode().setStyle("-fx-background-color: transparent;");
return curr;
}
}
In the corresponding css I refer to this skin as jewelsea mentioned. Et voila!
One little question is still left: why I'm not able to directly access this component via css?
ScrollBarSkin is a class representing the skin used to render the ScrollBar. Here is an extract from a default JavaFX style sheet:
.scroll-bar {
-fx-skin: "com.sun.javafx.scene.control.skin.ScrollBarSkin";
}
Here is a link to ScrollBarSkin.java in the JavaFX 8 source repository. Note that it is a com.sun class, so it is not part of the public API and could disappear or change API between minor JavaFX releases without notice.
You can override the default skin with your own skin via the following css in your user stylesheet:
.scroll-bar {
-fx-skin: "com.mycompany.control.skin.CustomScrollBarSkin";
}
I just made the name and path up, you can use whatever you want.
What the skin is allowing is programmatic control over the look of the a control (i.e. it's only incidentally related to css because css is one way to set the skin on a control).
Customizing Skins is documented (to a certain extent) in the OpenJFX wiki.
The skin customization relies on a new JavaFX 8 class called SkinBase, which forms part of the javafx.scene.control public API.
Customizing skins in versions lower than Java 8 is not recommended, because then you will be working with old, undocumented and unsupported private APIs which will not work with Java 8 and later. Customizing skins in Java 8 is fine because it relies on the public API.
I'm pretty sure from your question that this isn't really what you are looking for, but it is the answer to your question (at least as I understood it).
Is there a way to assign CSS style for the QTabBar close button?
Normally QTabBar can be styled, but I can't find its how button can be referenced from CSS.
As noted in a comment above, since Qt 4.6 you can use following style:
QTabBar::close-button {
image: url(close.png);
subcontrol-position: left;
}
It seems like there is not currently a way to style the close button via Qt style sheets. Not only is it not documented, there doesn't seem to be a style for it in src/gui/styles/qstylesheetstyle.cpp.
You can set the button using QTabBar::setTabButton() method.
You may want to submit it as a feature request on the Qt Bug Tracker.