How can I style a ComboBox "body" part not the dropdown?
As you can see on the screenshot I want to style just that part where you click and opens the dropdown and the dropdown should remain as it is.
If I try for example:
.combo-box-base .list-cell{
-fx-background-color: red;
}
everything goes red not just what I want.
I had a look at this question: Javafx combobox styling
but it didnt really helped me, it styles everything but not that specific part I need.
I have also looked with ScenicView, and I could locate it and add as style: -fx-background-color: red and it worked, but from code I could't manage it.
In ScenicView I saw the ComboBox has three components:
a StackPane a ListView and a ListCell. I want to style just the ListCell part.
Here is how it looks like if I add those line in my.css:
As you can see I don't want the dropdown to be styled.
How can I solve it.
Note: the arrow should remain as it is, just that part where the text is shown, as the second screenshot shows.
Related
I encountered a frustrating problem with styling a javafx graph. Hope that somebody can help me out.
Using the JavaFx-library I made a StackedBarChart and a LineChart combined in one scene:
StackPane stackpane = new StackPane();
stackpane.getChildren().addAll(lineChart,stackedBarChart);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
Style.css looks as follows:
.default-color0.chart-series-line { -fx-stroke-width: 4px;-fx-stroke: #3F48CC; -fx-stroke-dash-array: 12 12 12 12;}
.default-color0.chart-bar { -fx-bar-fill: #AA3B3B }
.default-color1.chart-bar { -fx-bar-fill: #FFC000 }
.chart-plot-background { -fx-background-color: transparent; }
The resulting image is:
Resulting image
Now I want to turn everything that is lightgrey (the background) into white. I tried that by adding the following styling:
.chart {-fx-background-color: white}
But this simple action makes the linechart (with the title of the chart) disappear:
Resulting image after adding style line
It seems that the .chart class refers to the background of the barchart, which is covering the linechart. Therefore: how to set the background of the entire image? Or should I make the background of the barchart-layer transparent and the background of the linechart-layer white? And if so: how to do that?
Thanks a lot!
If you use SceneBuilder, you can drop a control onto the design page, then click on View / Show CSS Analyser and it will open a window at the bottom that shows all of the styling properties for the selected object. If an object has multiple components on it, you can click on each one and see the related styling options.
Also, at the top of that lower window, you will see and arrow in a circle ... click on it to see more sub layer styling info that is related to whatever you have selected in the design window.
I'm using a custom JavaFX library called JFoenix that overhauls some JavaFX components with Google's Material Design. The problem I'm specifically running into is changing the text color of a ComboBox of Strings' selected item after it has been selected. This is my before screen, with the item in question circled.
The text turns from gray to black when I select an item from the ComboBox (see screenshot here). I want the text from the selected item to be the same color as the rest of the labels. Adding a -fx-text-fill or -fx-text-inner-color in Scene Builder doesn't work.
The only possible solution I've found is making the ComboBox editable and setting the color through its Editor after the user selects an option:
#FXML
private void handleComboBoxFormat() {
this.mpaaBox.getEditor().setStyle("-fx-text-fill: #eceff1;" + "-fx-background-color: #445566");
}
I don't like this solution because I don't want the ComboBox to be editable, and it just feels messy. Is there any other way to edit the text color? Thanks!
-fx-text-fill isn't defined in combo box.
But reading the CSS Reference Guide I see the structure:
.combo-box > .list-view > .list-cell
where .list-cell defines -fx-text-fill inherited from Labeled.
OK, so after messing with the CSS that #MouseEvent suggested, I figured out the solution.
.combo-box .list-view .list-cell affects the items in the ComboBox's list when you open the pop-up.
.combo-box .list-cell affects the label of the selected item, which was what I was having trouble accessing.
I understand that this is done in CSS (well SCSS) but I'm struggling with how to style it so that the MenuBar looks like text. I'm ok with the MenuItems as they are, I just want the MenuBar itself to look like links. A good example is the Help link at the top of StackOverflow, just to the left of the search box at the top of the screen..
By default in Vaadin it looks like buttons, and when I click on them the button is highlighted and has this extra border color as shown below:
I want to remove all that and just make it look like a link that you click on. The MenuItem styling is great, but I just want to make it look like text. I like the down carrot, as well as the styling for the MenuItems, it's just the MenuBar that I'd like to change. Below is an example:
I've been messing around with the css for a bit now and I just can't get the right style. Any help would be greatly appreciated. Again I'm just looking to remove the styling of the MenuBar and nothing else. So far I have:
.myMenuBar
{
border: none;
background-image: none;
background-color: myBackgroundColor;
box-shadow: none;
}
The problem is that there are still a number of style elements I'm struggling with:
For example I still have a blue highlighted button when I click. Also the popup menu is backgrounded to my custom color. I also have a separator line in black between the two elements. And although it's harder to see there is a fine white and grey line above and below the MenuBar to show some depth.
UPDATE: Added some css improvements but I'm still a ways away.
Even with the links in the comments just below the question I still struggled to find a solution. Eventually I ran into the Class ValoTheme and found I could do exactly what I wanted with one line of code. In fact it was better than what I was planning so kudos to the theme designers!
menuBar.setStyleName(ValoTheme.MENUBAR_BORDERLESS);
I'm new to both JavaFX and CSS. I'm using Scene Builder, and have an accordion that I want to use as a menu bar. I want the background of the accordion to either be transparent or to match the background of the page behind it, and the text to be fully opaque and a different color. Also, I do not want the arrows beside the text to appear. I've tried the various options that Scene Builder provides, but none enabled me to do either of these two things. Is this something I'll need to do with CSS, and if so, how?
I solved the issue with css. JavaFX uses a file called caspian.css for its standard styling.
An accordion module contains titled panes that consist of a title and a content area.
To remove the background color of the content you need to overwrite the styleClass of the titled panes:
.accordion .titled-pane > *.content {
-fx-background-color: null;
}
You could also assign a custom styleClass to your titled panes or accordion if you don't want to overwrite the style application-wide.
Hope this helps.
depending on what data I retrieve from the database, I need to update the color of a menu item. This is no problem for me, device.Style.Add("background-color", "red") works just fine for me. However, when I change the background color, it overrides my CSS style sheet, which is supposed to change the color to light grey on a:hover. Is there a way to update what the a:hover background color should be in my VB code? Thank you!!!
Use vb to attach a css class to the button. Then style that class to have the color you want.