I've noticed that buttons in JavaFX have rounded corners, which means when you have a grid of them there are little white spaces visible between.
This illustrates the problem
I'd like to make my buttons appear as rectangles, with right angled corners, is this possible? I assume this might be possible with CSS, but I can't find this question being asked before.
Thanks.
You can do Via CSS :
"-fx-background-radius: 0"
You can add your CSS file in several ways by code , by Inline , External file
By Code :
Button rectangleButton = new Button();
roundButton.setStyle("-fx-background-radius: 0");
By FXML Inline :
By FXML External :
mystyle.css file
.button{
-fx-background-radius: 0;
}
then choose directory of file to apply the style to your container
Related
I have a question. How can I make a circle checkbox in JavaFX? "-fx-background-radius" doesn`t work for me, also I want to when mouse is over checkbox to display a short describe for what this checkbox is create. How can I solved this? Thanks for helps.
For a CheckBox with rounded corners you would use CSS. It is helpful to look at the JavaFX CSS Reference Guide when you need to know what you can style from CSS. For instance, the section for CheckBox tells us there is a substructure; this includes a StackPane with the styleclass of box. It is this StackPane that is the "physical box" in the UI and what you want to round the corners of. In you're CSS file you'd have something like:
.check-box .box {
-fx-background-radius: /* enter you're desired radius here */;
}
Then you'd add the CSS file to your Scene via getStylesheets().add(...).
You also want to know how to display some information about the CheckBox when the mouse hovers over it, correct? To do this you would use a Tooltip.
CheckBox box = new CheckBox("Choose me!");
box.setTooltip(new Tooltip("I do something!"));
How can i change the grid lines color / can i change the grid lines color?
Cant seem to find a css solution.
You can use this css it work for me :
.mygridStyle Line {
-fx-stroke : red;
}
then you attach the css class with the scene builder or with myGrid.getStyleClass().add("mygridStyle");
As stated
in this question here
you shouldn't use GridPane to paint grid lines, you need to put content inside the cells, and then specify content borders. The visible grid line property if for debugging only, see doc.
I have a problem when trying to change the color of QTabBar's top line (blue line in the picture below).
Is this a separate part of tabBar (like scroller or tear) or its top border ? And how can I change its color with styleSheet and leave the other parts of tabBar unchanged?
P.S. : My tabBar::styleSheet returns an empty string, so I can't get current style and make changes in it.
If you're using a "system" style, you may not be able to change the color of the line (cause representation of UI elements is not handled by Qt but by the system).
You should define a complete style for QTabBar (and maybe QTabWidget too) that you can customize as you wish.
See the Qt Style Sheets Examples page.
Problem solved:
setStyleSheet("QTabBar::tab:selected { selection-background-color: red; }");
Here's the problem:
I tired to make the textarea from javafx have a black color, so i tried to add the parameter:
"-fx-background-color" with the value "black"
It did change something: Around the text area a black border appeared. I tried to change the background size with:
"-fx-background-insets" with the value "100" (for testing purposes, i know there are up to 4 values)
But nothing visual happend.
However, if i set the value to "-100", the screen 100 pixels outwards of the textarea is painted black. So, in theory, reversed parameter delivers the reversed result of what i want.
Therefore i ask: Why is it not working? I looked up other solutions, and they do it with the "-fx-background-color" parameter, so what a i missing here?
Use the following in an external css file:
.text-area .content {
-fx-background-color: black;
}
don't forget to include this css file, either through FXML or through code. You can use this tutorial.
I just found the solution to change the color of the background of TextArea in JavaFX. Write this in your controller class:
textarea.setStyle("-fx-control-inner-background: black;");
I was deep searching on the stackoverflow and eventually found it. The link is given below: Textarea javaFx Color
Happy coding!
After trying to find a solution for Centering Text on a Button with Offset, I'm doing now a custom component.
The goal is to make a button-like component that has an icon on one side and a centered text filling the rest of the button.
The component contains either two Label/ Buttons to display the Icon and text. Both of them have a background Image, defined in css.
The css looks like this for Icon and the text with exchanged image as background for text
#button-icon-cancel{
-fx-font-family: "Arial";
-fx-padding: 0,0,0,0;
-fx-background-color: transparent;
-fx-font-size: 28px;
-fx-graphic: url('images/button/cancel.png');
}
#button-icon-cancel:pressed{
-fx-graphic: url('images/button/cancel-pressed.png');
}
The images are loaded by setId(). Currently both components are added to a Panel before passing to the stage. They contain an OnClickEvent for processing.
Now to the actual question
How can I achieve that if one Component is clicked, the other one is getting the :pressed from css as well?
Adding the ClickEvent to the Panel is doing nothing (regarding clicking on either Label/ Button)
Adding both of them to a HBox, adding the Event to the HBox work in that regard, that I can click either component and the Event gets fired, BUT the :pressed State is only applied to the component you clicked.
Is it possible to give all childs the notification, that they should behave like they got pressed? Since we have a lot of small Icon, but only one background for the text, placing a Label over the whole thing create a lot of unneeded wasted Image space. Also this would cause the problematic for changing font color if not all css are changed at once (the label-over-button-solution with .setMouseTransparent(true) wouldn't change the font color of the text label since the label doesn't notice button is pressed)
First of all, JFX-8 will support wider range of css improvements, which will allow you to solve the issue easier.
To solve your issue, i can suggest the following : each node have a pressed property. You can add a listener on this property, and when it changes to true, use setStyle(String) method on needed nodes, and use setStyle(null | "") on changing to false.