Change MenuBar color in Scene Builder - java

How does one change the color of a JavaFX 2 MenuBar in JavaFX Scene Builder? I want to make it the same color as the menu bar in the Scene Builder. CSSĀ“s color and background-color doesn't seem to help.
I'd also be happy to know the color of the Scene Builder menu bar (in hexadecimal or decimal RGB).

You can use the fx-background-color css property to set the menu bar background color.
Regarding the Scene Builder menu bar background color, you can use:
-fx-background-color:
derive(#e0e0e0, -0.291),
linear-gradient(
to bottom,
derive(#e0e0e0, 0.353) 0%,
derive(#e0e0e0, -0.058) 100%
);
-fx-background-insets: 0, 0 0 1 0;
I extracted these css "coordinates" from Scene Builder jar, located at SceneBuilderInstalationRoot/lib/SceneBuilder.jar. In the jar, its on the package com.oracle.javafx.authoring.css_stylesheets, file SceneBuilderTheme.css. This css file uses a named constant -fx-color which I inferred to have value #e0e0e0.

You can find help about css directly in scene builder : on the menu View > Show CSS analyser
here you will can see that the menu bar use the class .menu-bar and have this -fx-background-color set with some color. So now you know that you have to put on the style of your MenuBar
-fx-background-color : thecoloryouwant
And that it.

Related

How to set width of AnchorPane to resize with parent JFXDialogLayout

I am trying to make the AnchorPane resize with its parent JFXDialoglayout. I tried this in scene builder, but wouldn't let me position/resize it correctly. Now I am trying to do it manually instead as seen below. As seen in the code I tried to bind the width and height of the AnchorPane to the JFXDialoglayout, but this did still not work. I also tried setting the pref height/width of them both equally, still did not work. The problem is that the height of the AnchorPane is smaller than the JFXDialogLayout but the width is the same. How do I make the heights equal?
private JFXDialogLayout getDialogLayout() {
JFXDialogLayout layout = new JFXDialogLayout();
layout.setPrefWidth(600);
layout.setPrefHeight(300);
AnchorPane pane = new AnchorPane();
pane.prefHeightProperty().bind(layout.prefHeightProperty());
pane.prefWidthProperty().bind(layout.prefWidthProperty());
Label heading = new Label("Heading");
Text body = new Text("This is the body of the dialog.");
JFXButton button = new JFXButton("ACCEPT");
pane.getChildren().addAll(heading, body, button);
layout.getChildren().addAll(pane);
return layout;
}
I have been making JavaFX apps using SceneBuilder and Netbeans for quite some time. What you are trying to do, can be done easily at the Tab "Layout" and more specific in the tab "Anchor Pane Constraints". Inside the four boxes you have to put the standard distance you like, between the Hbox sides and the Anchor Pane outer sides. Please, check the screenshot below, with my example for a Horizontal Box inside an Anchor Pane. The HBox gets smaller or bigger when the user resizes the Anchor Pane.

How to get back the onclick effect on a button in JavaFX

I looked for a solution on this particular issue & found a few ones on Silverlight & JavaScript, but not on JavaFX.
Now on the issue:
I am designing a GUI in JavaFX where I have added two buttons: ADD & REMOVE
I have styled the ADD button using CSS, but it has lost its hovering & onclick effect. I have attached a couple of images for better understanding of the issue
If you look at this photo here, you'll see that when the REMOVE button is clicked, it slightly changes its color to give the effect that it is being clicked currently. Also when the cursor hovers over it, it turns slightly brighter than it usually is.
The code for this button is given below
VBox rightBox = new VBox(remBttn);
rightBox.setPadding(new Insets(10));
rightBox.setAlignment(Pos.CENTER);
remBttn.setPadding(new Insets(100,0,100,0));
remBttn.setPrefWidth(100);
remBttn.setOnAction(
new EventHandler<ActionEvent>()
{
public void handle(ActionEvent ae)
{
myLabel.setText("You Clicked The REMOVE Button");
}
});
remBttn.setFont(Font.font(20));
However, if you look at this photo here, you'll notice that hovering and clicking have no effects on it. I don't know much about CSS, so I copied a snippet of code from a random Website to style my button. But I think that is where I messed it all up.
The code for that give below:
VBox leftBox = new VBox(addBttn);
leftBox.setPadding(new Insets(10));
leftBox.setAlignment(Pos.CENTER);
addBttn.setPadding(new Insets(100,0,100,0));
addBttn.setPrefWidth(100);
addBttn.setStyle("-fx-background-color: #c3c4c4, linear-gradient(#d6d6d6 50%, white 100%), radial-gradient(center 50% -40%, radius 200%, #e6e6e6 45%, rgba(230,230,230,0) 50%); -fx-background-radius: 30; -fx-background-insets: 0,1,1; -fx-text-fill: black; -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1 ); -fx-focus-color: transparent; -fx-base: coral;");
So I want to know what methods or properties can be used to bring back the same effects without changing the style.
The moment you change the background of the button,It will lose its default hover and click effect,So I think the better way of doing it is to set the hover and click effect in css.
By the way instead of setting style again in code, just create a css file in your src folder then link it to your scene using this.
scene.getStylesheets().add(getClass().getResource("your_file_name.css").toExternalForm());
Then add an id to your add button using addBttn.setId("addBttn"); Then
refer to it in your_file_name.css like
#addBttn{
/*Your custom default button style*/
}
#addBttn:hover{
/*Your button style on hover*/
}
#addBttn:pressed{
/*Your button style on pressed*/
}
Hope this solves your problem.

style pressed button in JavaFX

I've got a Button in my FXML file and i give a style to it by below CSS
.button {
-fx-background-color: linear-gradient(#ff5400, #be1d00);
-fx-background-radius: 30;
-fx-background-insets: 0;
-fx-text-fill: white;
}
as you can see the button has a new awesome style, but whenever i click on it, it remains as like as before and you can't understand is it clicked or not...
As I searched, I found one solution in this link: Pressed CSS, but if you notice it is The CSS that is used by Web Browsers and JavaFX does not support it.
so what is the solution? I want my button changes its appearance when the users hit or click it.
You need to add the psuedoclass state pressed to you css and add new css to it, which will differentiate your current button css with that when pressed :
.button:pressed {
// Your new css
}
For changing the style while hovering the button use :
.button:hover {
// Your new css
}
For better understanding of what style you can add for styling the button, you can go through How to make a button appear to have been clicked or selected?
for arrayLists on javaFX, try this on the CSS to change colors on mouse click:
.list-cell:selected { -fx-background-color: yellow; }

Javafx change Tab X to image icon from url

How could I change the Tabs close icon X to an image in javafx? I have tried setGraphic(), but it only takes a node... the image i want to set it to is http://eclipse-icons.i24.cc/ovr16/progress_rem.gif
Make the image a valid node using ImageView, but that seems to be for icons.
Tab tab = new Tab();
Image image = new Image("http://eclipse-icons.i24.cc/ovr16/progress_rem.gif");
ImageView iv = new ImageView(image);
tab.setGraphic(iv);
Get rid of the default shape in CSS or write your own or use a background image
.tab-close-button {
-fx-background-color: transparent;//-fx-mark-color;
-fx-shape:null;
-fx-background-image: url("/progress_rem.gif");
}
You'll have to provide your own click handler without the css shape, or something to click on.
This is what you get with css.

javafx changing default style of menu item

I want to change the default style of JavaFX menu item, so adding css but not getting worked. So how can I change the default style of menu item? Also how can I check that whether my css is connected or not?
.menu-item:focused {
-fx-background: -fx-accent;
-fx-background-color: #AA0000;
-fx-text-fill: white;
}
used this but not working.
Problem solved
setting the style Sheet for the Current scene thats why not Working
Set style sheet to root then define your css class and used it to menu item to solve problem
this.getScene().getRoot().getStylesheets().add("com/proj/folder/styles/menuitemcss.css");

Categories