Using JavaFX: Changing the text color of a selected row in an unfocused TableView

My application utilizes row selection mode (

table.setCellSelectionEnabled(false)
)

Within my stylesheet:

.table-row-cell:selected {
   -fx-background-color: steelblue; 
   -fx-text-fill: red !important;
}

While the -fx-background-color property functions properly, the -fx-text-fill does not. The text color of the selected row remains black (when the TableView is unfocused) or changes to white (if the TableView gains focus).

Answer №1

Here's a solution that has been effective for me, even though there may be simpler alternatives:

.table-row-cell:selected {
   -fx-background-color: steelblue; 
}
.table-row-cell:selected .text {
       -fx-fill: red ;

}

Answer №2

When working with JavaFX 8 and utilizing the Modena style sheet, the color of selected row text is determined by the brightness of the background. For instance, white text is used for dark backgrounds and black text for light backgrounds. To customize this behavior, you can override it by directly setting the text background color. This will then be utilized as the text color for selected rows:

.table-row-cell:selected {
   -fx-background-color: steelblue; 
   -fx-text-background-color: red;
}

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

What is the process of including a CSS class in a NAV anchor tag on WordPress?

I recently started using Bootstrap 4 and have structured my menu in the following way: <ul class="navbar-nav mx-auto justify-content-center"> <li class="nav-item"> <a class="nav-link" href="index.php">HOME</a> </ ...

What is the functionality of {all: initial} and how does it address issues with default values?

Why do paragraphs inherit properties like line-height and text-align from the div element? If values for these properties are: normal -> for line-height [i.e. font-size = 16px (initial / default value) * normal (value is usually around 1.2 -> 19.2 ...

Locate every div element that contains a span id matching any word in a specified list

I'm attempting to create a script that will add a class based on whether or not a list item's span id contains certain words from a list. The list follows this structure: <div id="main_list"> <li class> <a data-item_ ...

Guide on dragging and dropping without losing the item, allowing for continuous drag and drop functionality

function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("text"); ev.target.appendChild(document.getElementB ...

Exploring the possibilities of using rem, em, and px for setting image dimensions

I am in need of clarification on the use of different units for image dimensions. Despite my research, I have not been able to find a consistent answer. Some sources suggest using only rem/em instead of pixels, but I am unsure if this also applies to image ...

What is the best way to incorporate width adjustments in an image source for a responsive website?

Currently learning CSS and experimenting with it on an HTML page. For reference, I'm using this link. Encountering an issue with a responsive header image that adjusts size based on device (small on mobile, large on desktop). Is it possible to achiev ...

What could be causing the unexpected behavior of the flex property?

Check out the code snippet below: @import url("https://fonts.googleapis.com/css2?family=Inter&display=swap"); @import url("https://fonts.googleapis.com/css2?family=Lexend+Deca&display=swap"); * { box-sizing: border-box; margin: 0; padding: ...

I am struggling to remove the div from its normal flow as it stubbornly remains positioned below

Is there a way to add a "contact" card to my website's right-top corner in a sticky position? I currently have a div block in that area which is blocking the contact card. Can anyone suggest a solution for this? https://i.stack.imgur.com/umC7B.jpg &l ...

Is it possible to achieve a capsule shape using border-radius without specifying a fixed width or height?

Can a capsule shape be created using border-radius without specifying a width or height? I am looking to have the left and right sides of the capsule fully rounded while keeping the horizontal length straight. Setting the radius to 50% does not achieve th ...

Tips for preventing redundancy in html theme construction by using bootstrap classes only once

As I embark on creating an HTML theme, I have decided to incorporate Bootstrap 4. One challenge I encountered was the need to repeat Bootstrap classes in various places, such as: <div class="row border border-top-0 mt-2 p-2 bg-info">One</div> ...

Troubleshooting: Unable to preview Facebook Page plugin

When I visit the Facebook developer site to get the code for a Facebook page plugin, I use this link. The preview feature works perfectly with pages like "facebook.com/Nike", but when I try it with my own page, "facebook.com/BargainHideout", it doesn&apos ...

fullpage.js: the content exceeds the height limit

I am currently working on customizing the jquery script fullpage.js for a website built on the French CMS "SPIP" (). This script is used to create a one-page website with both horizontal and vertical navigation. However, I have encountered an issue with ...

Error encountered when attempting to trigger a Bootstrap dropdown within a designated div

When using React JS, I encountered an issue when trying to trigger a dropdown that was nested inside a div with the class name "row". Initially, I placed the data-toggle and data-target attributes inside the div, like so: <div className="row"> < ...

Is there a way to use Media Queries to require CSS to load an image?

Here is the CSS code I am using: html { background: url(../img/header_mobile.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } /* Smal ...

Tips for defining conditions within the style attribute in JSP

Below is the code that I attempted: <div style="width:85%;"> <input class="formbutt" value="AddNew" title="AddNew" type="button" style="{(${projectEnvironmentBean.divStyle}=='dipslay:none') ? 'display:block' :'display: ...

The dropdown menu is obscured by the section

My header contains a dropdown menu that is being hidden behind the section. https://i.sstatic.net/SnQNa.png The Logout button is located in the top right corner, underneath the name, and it is also not visible. I have attempted to apply the following styl ...

Condensing CSS and Javascript using Java or Scala

I have a requirement to dynamically generate CSS/JavaScript for my project. After generating this code (most likely with PHP), I need to retrieve the string, minify it, and then save the minified file. I tried looking for a Java/Scala tool that can acco ...

CSS - when "start" is not 1, an alternative to the "nth-child" selector

Imagine a scenario where you have a list of questions that start at 0 and you want to apply CSS styling based on their value. For instance, consider the following list... <b>How are you feeling?</b> <ol start="0"> <li>Great< ...

Clicking on the Bootstrap tabs causes them to shift position

I have come across an unusual issue with my website. While on the home page, clicking on a tab functions normally. However, when attempting to switch from one tab to another (such as News to Beats, Beats to News, News to Home, or Beats to Home), the tab co ...

Display the table by pressing the button

Check out my code below <script> $(document).ready(function(){ $("button").click(function(){ $("table").toggle(); }); }); </script> <!--Code for the Technical Specifications Button--> <div ...