Styling JavaFX ChoiceDialog with CSS

I'm currently struggling with customizing the appearance of a ChoiceDialog in my JavaFX application using CSS. While I've successfully applied styles to other dialog panes, it seems that the ChoiceDialog is not responding as expected, possibly due to unfamiliar elements.

My goal is to override the modena css and modify the look of the ChoiceDialog. I have attempted different CSS configurations, such as:

.dialog-pane {
-fx-background-color: black;
}

.dialog-pane .label {
-fx-text-fill: white;
}

.dialog-pane:header .header-panel {
-fx-background-color: black;
}

.dialog-pane:header .header-panel .label {
-fx-font-style: italic;
-fx-font-size: 2em;
}

I also tried:

.choice-dialog .dialog-pane {
-fx-background-color: black;
}

.choice-dialog .dialog-pane .label {
-fx-text-fill: white;
}

.choice-dialog .dialog-pane:header .header-panel {
-fx-background-color: black;
}

.choice-dialog .dialog-pane:header .header-panel .label {
-fx-font-style: italic;
-fx-font-size: 2em;
}

I've experimented with several variations of these CSS rules but haven't achieved the desired results so far. Additionally, I attempted to change the icon displayed on the ChoiceDialog without success:

.choice-dialog.dialog-pane {
-fx-graphic: url("dialog-warning.png");
}

However, none of these modifications seem to have any effect. I recently cleared my custom CSS file and retried the mentioned configurations, but only the DialogPane's appearance was altered, not the ChoiceDialog itself.

Below is how I created the ChoiceDialog:

ChoiceDialog<String> dialog = new ChoiceDialog<>("district", choices);
dialog.setTitle("Object Selection");
dialog.setHeaderText("Which object should the file inherit from?");
dialog.setContentText("Default Object:");

Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow();
dialogStage.getIcons().add(icon);
dialogStage.initOwner(stage);

Optional<String> response = dialog.showAndWait();
response.ifPresent(chosen ->
{
    //It does something...
});

In another instance, I utilized this code to create a different type of dialog:

Dialog<ObservableList<DataFilter>> dialog = new Dialog<>();
dialog.getDialogPane().setPrefSize(620, 430);
dialog.setTitle("Field Filter");
dialog.getDialogPane().getButtonTypes().addAll(save_bt, cancel_bt);
dialog.initOwner(stage);
dialog.setResultConverter((ButtonType b) ->
{
    if (b == save_bt)
    {
        return FXCollections.observableArrayList(dataFilters);
    }
    return null;
 });

 Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
 stage.getIcons().add(icon);

Answer â„–1

It took me about an hour of experimenting to figure this out. There are a few other selectors located in modena.css under "STYLES FOR THE DEFAULT LISTVIEW-BASED COMBOBOX"

.dialog-pane{
-fx-background-color: #7160DC;
   }
 .dialog-pane > *.button-bar > *.container{
 -fx-background-color: #7160DC;
  }
  .dialog-pane > .content .label{
  -fx-font-size: 15px;
  -fx-font-weight: bold;
   -fx-text-fill: orange;
   }
  .dialog-pane:header .header-panel{
   -fx-background-color: #9589DF;
    }
    .dialog-pane:header .header-panel .label{
    -fx-font-size: 18px;
    -fx-font-style: italic;
     }

   .button{
    -fx-background-color:black;
    -fx-text-fill:white;
    }

  .button:hover{     
  -fx-background-color:orange;
   -fx-text-fill:black;
   -fx-font-weight:bold; 
   }

   /* styles background of cover choice*/
   .combo-box {
  -fx-background-color: black;
  -fx-font-weight: bold;
   }
  /* styles text of cover choice*/
  .combo-box > .list-cell {
  -fx-text-fill: yellow;
  }

 .combo-box-popup > .list-view {
-fx-background-color:black;
-fx-background-insets: 0, 1;
-fx-effect: dropshadow( gaussian , rgba(0,0,0,0.2) , 12, 0.0 , 0 , 8 );
 }

.combo-box-popup > .list-view > .virtual-flow > .clipped-container > .sheet >  .list-cell {
-fx-padding: 4 0 4 5;
-fx-background: black;
}

.combo-box-popup > .list-view > .virtual-flow > .clipped-container > .sheet   
> .list-cell:filled:hover {
-fx-background-color: orange;
 -fx-text-fill: black;
 }

 //add the above .css file as stylesheet

ChoiceDialog dialog = new ChoiceDialog();
    dialog.setTitle("Confirmation");
    dialog.setContentText("Some Text");
    DialogPane dp = dialog.getDialogPane();
    dp.getStylesheets().add(getClass().getResource("myCssFile.css")
    .toExternalForm());
    Optional<String> result = dialog.showAndWait(); 

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

How does the size of a font affect the amount of screen space a character occupies in pixels?

I am currently working on a custom user interface that requires precise measurement of how many pixels are taken up by a specific string of text. My attempts to control the character size using the font-size property have been met with unexpected results. ...

Creating a multi-step progress bar in Yii2 that showcases completed steps using jQuery

Is there a way to automatically transition from one state to another once the order status changes in Yii2? var i = 1; $('.progress .circle').removeClass().addClass('circle'); $('.progress .bar').removeClass().addClass(&a ...

The full screen menu is exclusively displayed in the navigation bar

My HTML and CSS code is causing an issue where the full-screen menu only appears in the nav bar. This problem seems to be specific to Safari. To solve the issue, I need to remove the following code: .nav { position: fixed; } However, I still ...

Exploring the Power of JQuery Load and CSS styling

Currently, I am dynamically loading text into a div. However, I am encountering an issue where the content below this div is constantly shifting depending on the loaded text. Is there a way to restrict the space allocated to the div with the dynamic conte ...

The best way to organize and position a Label and TextBox in C#

I need help styling the aspx file. The Label and TextBox elements are not aligned properly. I want the Label and TextBox to be positioned side by side with appropriate spacing. <div class="col-md-12"> <p> ...

What is the best way to incorporate a Django variable as the width parameter in a style tag within HTML?

I'm attempting to utilize a Django variable as the percentage width value within a style tag in HTML, but it's not functioning correctly. Strangely, I've discovered that using curly braces {} within style tags is prohibited—this contradict ...

I want to use flexbox to center three divs on my webpage

I am trying to align 3 divs inside a flex container in the center of the page with equal distance between them and also from the edge of the page. .container { display : flex; width : 60%; } .para { width : 33%; padding : 1em; borde ...

Having trouble with your jQuery slideDown menu?

I am facing the exact same issue I had last week. Here is an example of my HTML code: <article class="tickets"> <div class="grid_12 left"> <div class="header"> <i class="ico ...

Guide on making a dynamic table with HTML and CSS featuring square cells

Looking to design an 8x8 table using HTML and CSS, with the first column and row functioning as headers (ideally with header row height equal to header column width), and all table body cells being square. Shown below is the current HTML and CSS code: < ...

After refreshing the page, users are redirected back to the login page

On my website, I created a main page and an index.html page that redirects to the main page through a login panel. The issue I am encountering is that when I log in successfully on the main page and then refresh the page, it takes me back to the login pag ...

Personalize or delete the spacing within an ion row

Currently, I am delving into the world of Ionic app development. Although I have grasped the concept of the Grid layout, I find myself hitting a roadblock when it comes to adjusting or removing spaces between rows 2 and 3 in my app interface, as illustrate ...

I am experiencing issues with my button not responding when I click on the top few pixels

I've created a StackBlitz version to illustrate the issue I'm facing. It seems like the problem might be related to my CSS for buttons... Essentially, when you click on the button at the very top few pixels, it doesn't register the click an ...

Adjust the placement of image when changing the size of the window

Is there a way to prevent an image with a fixed position from covering up page content when the browser window is resized? <div > <img id="img1" class="wrapperImage"></img> </div> <style type="text/css"> .wrapperImag ...

What is the process of utilizing jQuery to hover over a relevant cell?

I'm interested in learning how to implement jQuery to highlight related tables. Initially, I explored this JS fiddle and discovered a method for highlighting both vertically and horizontally. I conducted several searches to find a similar approach, ...

No JavaScript needed for this CSS framework

I have been tasked with creating a website without the use of JavaScript, following very specific instructions. Furthermore, it must be compatible with iPhone and other mobile devices, while still adhering to the no JavaScript rule. I am open to utilizing ...

Set the class of an element dynamically using ng-class and detect changes with ng-change

I want the input field to initially have the class .form-control-error. When the user clicks on the field and starts typing, I would like it to change to .form-control-success. I attempted the following code but couldn't get it to update. The ng-chan ...

Material UI Grid List rows are displaying with an unusually large gap between them, creating a

Currently, I am utilizing Material UI in combination with Reactjs. One particular issue that I am encountering involves the Grid List Component. In my attempt to establish a grid of 1000x1000px, I have specified the height and width within the custom gridL ...

What is the best way to utilize variable fonts with Google Fonts?

Traditional fonts typically require a separate file for each weight variant, such as 300, 400, and 500. However, with variable fonts, all weight combinations can be accessed through a single compact font file. This is extremely advantageous for web design. ...

Aligning a sprite at the center of a div background

My button has a unique design where it consists of a sprite set as the background image of a div. The sprite sheet is laid out horizontally, and I have also scaled down the source image to fit the div. .button { background: url(sprite.png); backgr ...

Gallery of Disappearing Images

I am encountering issues with the image gallery on my website, as it seems to create a space to the right when viewed on screens smaller than 350px. This results in a gap on the entire right side of the page. My goal is to make this image gallery responsiv ...