I am trying to make the arrow button disappear entirely from my ComboBox and at the same time i want to make my ComboBox open the dropdown menu when i click on it.
Firstly, with what i have made the arrow is transparent but still works. So what i want is to delete it entirely. How am i suppose to do that?
ComboBox Java Code
searchBar = new ComboBox<>();
searchBar.setEditable(true);
searchBar.setMinWidth(1100);
searchBar.setPromptText("type here");
CSS Code:
.combo-box {
-fx-border-width: 0.2px;
-fx-border-color: #87C6C8;
-fx-border-radius: 45px;
-fx-background-radius: 45px;
-fx-font-size: 15px;
-fx-font-weight: 100;
-fx-font-family: 'arial';
}
.combo-box .arrow,
.combo-box .arrow-button{
-fx-background-color: transparent;
}
.combo-box-base:editable > .text-field{
-fx-border-width: 0.5px;
-fx-border-color: #87C6C8;
-fx-border-radius: 50px;
-fx-background-radius: 50px;
-fx-font-size: 15px;
-fx-font-weight: 100;
-fx-font-family: 'arial';
}
Result:
How can delete that?
Secondly, how can i make an action when i click the ComboBox the menu drops down?
Any help is appreciated.
Thanks in advance!
Having a Node for example VBox I am trying to add a border and there are 2 ways I can think of - using css or using new Border () etc..
How can I remove part of the border ? i.e remove the bottom part of the border
You can specify different styles for the borders on different sides
Using Border
#Override
public void start(Stage primaryStage) {
Region root = new Region();
root.setBorder(new Border(new BorderStroke(Color.RED, Color.RED, Color.RED, Color.RED,
BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.NONE, BorderStrokeStyle.SOLID,
CornerRadii.EMPTY, new BorderWidths(5), Insets.EMPTY)));
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
Using inline css
root.setStyle("-fx-border-style: solid solid none solid; -fx-border-width: 5; -fx-border-color: red;");
Using a css stylesheet
.root { /* modify the selector according to your needs */
-fx-border-style: solid solid none solid;
-fx-border-width: 5;
-fx-border-color: red;
}
none doesnt work on javafx 13. I tried changing it to hidden and it works.
.root { /* modify the selector according to your needs */
-fx-border-style: solid solid hidden solid;
-fx-border-width: 5;
-fx-border-color: red;
}
Setting border-width to 0 worked (JavaFX 17): Example:
#header
{
-fx-border-width: 0 0 2px 0;
-fx-border-color: black;
-fx-border-style: solid;
}
Here you can get border only at bottom - order: Top, right, bottom, left.
When vboxs are focased can we use css to change them?
#vbox{
-fx-border-radius:8;
-fx-border-width:2;
-fx-border-color: #333333;
}
//this works
#myvbox:hover {
-fx-border-color: #455A64;
}
//this does not
#myvbox:focused{
-fx-border-color: #000000;
}
Hover works fine. But trying to set color of focused vbox it does not work.
I wan't to change the color of any button in my application from red to blue fluent when the mouse is over it.
This is my css code so far:
.button{
-fx-background-color: rgb(225,0,0);
}
.button:hover{
-fx-background-color: rgb(0,0,255);
transition: -fx-background-color 2s;
}
Now I'm looking for something like this:
.button:hover{
transition: -fx-background-color 2s;
}
Hello Fellow StackOverflow Users, this is my first post/question and hopefully i'm not violating any rules/ect.
Unfortunately I am unable to post a picture, but I will put this here for a reference.
http://i.imgur.com/M0uckkg.jpg (Before Button Click)
OT: On the picture above, I am attempting to make the button's background completely transparent besides the text.
http://i.imgur.com/bFOEOVC.jpg (After Button Click)
Everything works out until I click the button then shadows appear on the side.
Here is what I have tried...
CSS
.toggle-button {
-fx-text-fill: black;
-fx-base: transparent;
-fx-background: transparent;
-fx-focus-color: transparent;
-fx-border-color: transparent;
-fx-effect: null;
}
.toggle-button:selected {
-fx-text-fill: black;
-fx-base: transparent;
-fx-background: transparent;
-fx-focus-color: transparent;
-fx-border-color: transparent;
-fx-effect: null;
}
The java code is just a plain simple application with a ToggleButton.
Special Thanks in Advance!
- Bart
I wouldn't recommend modifing the main color palette (-fx-base and others) for just one control. This makes sense if you're trying to style all of them.
Looking at how is defined in modena.css:
.toggle-button {
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border,
-fx-inner-border, -fx-body-color;
-fx-text-fill: -fx-text-base-color;
}
.toggle-button:selected {
-fx-background-color: -fx-shadow-highlight-color,
linear-gradient(to bottom, derive(-fx-outer-border, -20%), ...),
linear-gradient(to bottom, derive(-fx-color, -22%) 0%, ...);
}
.toggle-button:selected:focused {
-fx-background-color: -fx-focus-color,
linear-gradient(to bottom, derive(-fx-color, -22%) 0%, ...),
-fx-faint-focus-color, linear-gradient(to bottom, derive(-fx-color, -22%) 0%, ...);
}
you will need to change all of them: -fx-shadow-highlight-color, -fx-outer-border,...
Instead, I'll just override the style of the toggle button with your requirements:
.toggle-button,
.toggle-button:focused,
.toggle-button:selected,
.toggle-button:selected:focused {
-fx-background-color: transparent;
-fx-text-fill: black;
}
NOTE I've edited my answer since, as #eckig suggests, it's redundant to apply the same color to the different comma separated values.
If you want to remove the button-like optics completely, I would suggest you to remove all existing styles and add your own style class as the only style class:
ToggleButton toggleButton = new ToggleButton("Login");
toggleButton.getStyleClass().setAll("my-custom-button");
Now you can apply only the styles you need:
.my-custom-button {}
Special Thanks to both of you, Jose & Eckig. I managed to edit my code with both your suggestions and it fixed the issue right away!
Here is a reference for anyone in the future.
Button Code
ToggleButton button= new ToggleButton("Login");
button.getStyleClass().add("custom");
CSS
.custom,
custom:selected {
-fx-background-color: transparent;
-fx-text-fill: black;
}