Eclipse compatibility issue with JavaFx Css causing styling problems

Recently delving into JavaFx, I decided to try my hand at setting up a custom style. Following a tutorial, I encountered a stumbling block that I just can't seem to overcome. No matter what changes I make in the CSS file, it simply doesn't reflect on the application.

public class UserLogin extends Application{

public static void main(String[] args){
    launch(args);
}

@Override
public void start(Stage primaryStage){
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25,25,25,25));

    Scene scene = new Scene(grid, 300, 275);
    scene.getStylesheets().add(getClass().getClassLoader().getResource("login-style.css").toExternalForm());  

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);         
    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);  
    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    btn.setOnAction(new EventHandler<ActionEvent>(){
        @Override
        public void handle(ActionEvent e){
            actiontarget.setFill(Color.FIREBRICK);
            actiontarget.setText("Sign in button pressed");
        }           
    });                         

    grid.getStylesheets().add("login-style.css");

    primaryStage.setScene(scene);
    primaryStage.show();
}}

Working within Eclipse with Java 7.1, the curious thing is that it does recognize the CSS file. This is evident because if I mistakenly reference a non-existent file, it fails to compile. I've experimented with several code snippets for the CSS file, and for now, it resembles something like this:

.root{
    -fx-font-size: 14pt;
    -fx-font-family: "Tahoma";
    -fx-base: #DFB951;
    -fx-background: #A78732;
    -fx-focus-color: #B6A678;
}

Answer №1

You have the option to incorporate the Cascading Style Sheet into the Scene. Therefore, if implementing it does not resolve the issue, you can alternatively configure the style directly within the code as an initial attempt.

One way to achieve this is by:

Component.setStyle("Insert CSS Code Here");

Answer №2

While going through the Oracle tutorial, I encountered a similar issue with Eclipse. Have you verified that there is only one "login2.css" file in your project and that it is placed in the bin folder?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to utilize Java to send an email that includes the content displayed in the console to the recipient?

I'm currently developing a Selenium WebDriver program that generates a table in the console displaying which apps have passed or failed my test. I would like to send this table to someone once the program has finished running. Below is the code snippe ...

The latest version of Spring Boot does not provide a default 401 JSON response, whereas it was available in previous

It seems that Spring Boot version 2.6.3 no longer includes default JSON responses with 401 status codes and some other responses. @Override public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResp ...

Methods for Expanding a Div within an Oversized Row, Despite Height Constraints

I have a situation where I need to adjust the height of a cell in a table. One of the cells contains a larger element that causes the row to expand vertically. I also have another cell with a div element set to 100% of the cell's height. However, I wa ...

CSS uses color parameters in the same way

Apologies, I spent a few years immersed in the world of IT. Now, onto my query: I have a lengthy ".css" file with numerous structures like color: #567567; within it. Is there a way to utilize a construction similar to color: $mycolor or is this not po ...

Divs gracefully appear one after the other in a sequential manner

I am attempting to showcase a sequence of 4 divs in a row using the ease-in CSS transition feature. I came across this example that demonstrates what I am aiming for: http://jsfiddle.net/57uGQ/enter code here. However, despite my best efforts, I am unable ...

The Firefox browser is not rendering the website correctly

After successfully programming a website with the FullPage Slider from this source, everything was working fine except in Firefox. Specifically, one section containing a table with image overlay hover effects from these effects library was not functioning ...

Options menu in an Android Studio application

Having just begun my journey with Android Studio, I am facing difficulties in creating a menubar. Despite my efforts to find solutions, none of them seem to work out. I attempted the following code snippet, but I feel stuck at this point: public class Ma ...

How to create a heading within a Bootstrap list item?

Attempting to replicate this layout using Bootstrap 3 This is my current progress <ul class="list-group"> <li class="list-group-item> Cras justo odio </li> <li class="list-group-item> Dapibus ac facilisis in </l ...

Position card action buttons at the bottom using Material UI

I have been working on an app using ReactJS and incorporating MaterialUI (for React) along with React Flexbox. One issue I've encountered is the struggle to position the card buttons at the bottom, which seems to be a common problem across different ...

When running Javascript, the code is displayed rather than being executed

I have a current MVC - C# application that generates various "popup" screens containing necessary information. I wanted to apply the same method to create a popup displaying a version history (listing the Versions with their corresponding changes). Howeve ...

Is the text in the password field displayed as masked?

Is it possible to confirm if the text entered in the PASSWORD field is being shown in a masked format? ...

Excessive content spilling over the div container

Hello everyone I've been trying to set up a div that includes an image, a title, and some text. I want the image to be aligned on the left side, with the title and text following on the right. However, I'm having an issue where the text is overf ...

Is there a way to output two webelements in a single print statement?

Below is the code snippet I am using: WebElement firstNameInput = driver.findElement(By.name("firstname")); firstNameInput.sendKeys("John"); WebElement lastNameInput = driver.findElement(By.name("lastname")); lastNameInput.sendKeys("Doe"); System.ou ...

What is the correct way to customize colors for specific components in Material-ui?

Struggling with theming in Material-UI, particularly when it comes to customizing element colors. Some elements default to 'theme.palette.main.dark' and I want to override this behavior. For example, the TextField and SpeedDial components automa ...

When resizing the window, divs shift positions and prevent the use of the horizontal scrollbar

I'm encountering an issue with my website layout. Specifically, I have a full-width navbar with some divs nested within it. However, when the page is resized, the position of these divs in the navbar shifts and a scrollbar appears at the bottom of the ...

IE causing Ul LI Menu to not display as Block

I'm encountering an issue with my menu. It displays correctly in Firefox and Chrome, but in IE8 it appears as a vertical list instead of a horizontal menu. I have included a doctype and I am linking to the HTML5 JavaScript via Google, so I'm not ...

Click on the sidebar to reveal the dropdown menu

I have been working on a project and have successfully created a navbar with a dropdown menu that includes a hover effect. Now, I am attempting to implement a click event to open and close the dropdown's submenu, but unfortunately, it is not working. ...

Display an HTML checkbox with intricate design features

I have a simple question - how can I print a green checkbox with a white check mark (Ctrl + P) without it turning black and white? This solution currently works with Bootstrap 4.0.0, but needs to be compatible with bootstrap 3.3.7. I've managed to cr ...

What is the best way to keep wp_nav_menu expanded while accessing submenu links?

Recently, I joined the Wordpress community and am currently in the process of converting a static HTML site to the WP platform. Almost everything is working smoothly except for the navigation menu. I am attempting to utilize the built-in navigation featur ...

Unable to adjust the text color to white

As someone who is new to Typescript, I'm facing a challenge in changing the text color to white and struggling to find a solution. I'm hoping that someone can guide me in the right direction as I've tried multiple approaches without success ...