Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:11:57+00:00 2026-06-15T12:11:57+00:00

i need create JavaFx TableView with multicolor rows (color1 for low priority, color2 for

  • 0

i need create JavaFx TableView with multicolor rows (color1 for low priority, color2 for medium priority etc.). I have created CellFactory

public class TaskCellFactory implements Callback<TableColumn, TableCell> {

@Override
public TableCell call(TableColumn p) {

   TableCell cell = new TableCell<Task, Object>() {
        @Override
        public void updateItem(Object item, boolean empty) {
            super.updateItem(item, empty);
            setText(empty ? null : getString());
            setGraphic(null);
            TableRow currentRow = getTableRow();
            Task currentTask = currentRow == null ? null : (Task)currentRow.getItem();
            if(currentTask != null){   
                Priority priority = currentTask.getPriority();
                clearPriorityStyle();
                if(!isHover() && !isSelected() && !isFocused()){
                    setPriorityStyle(priority);
                }
            }
        }

        @Override
        public void updateSelected(boolean upd){
            super.updateSelected(upd);
            System.out.println("is update");
        }

        private void clearPriorityStyle(){
            ObservableList<String> styleClasses = getStyleClass();
            styleClasses.remove("priorityLow");
            styleClasses.remove("priorityMedium");
            styleClasses.remove("priorityHigh");
        }

        private void setPriorityStyle(Priority priority){
            switch(priority){
                case LOW:
                    getStyleClass().add("priorityLow");
                    break;
                case MEDIUM:
                    getStyleClass().add("priorityMedium");
                    break;
                case HIGH:
                    getStyleClass().add("priorityHigh");
                    break;
            }
            System.out.println(getStyleClass());
        }

        private String getString() {
            return getItem() == null ? "" : getItem().toString();
        }
    };
    return cell;
} }

and css

.priorityLow{ -fx-background-color: palegreen; }
.priorityMedium{ -fx-background-color: skyblue;}
.priorityHigh{ -fx-background-color: palevioletred;}

But i still need highlight selected rows. How can i do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:11:59+00:00Added an answer on June 15, 2026 at 12:11 pm

    Instead of setting the background color for the entire cell in your css, just set the -fx-control-inner-background. Then you will have the default accent, hover and focus rings still available. Also remove the if statement around your setPriorityStyle call of course.

    If you also want to override things like the default accent (selected) color or the hover color, you can also do this as in the css below – not sure if the highlight overrides are really recommended though, guess it would depend on your app and desired user experience.

    .priorityLow { 
      -fx-control-inner-background: palegreen;
      -fx-accent: derive(-fx-control-inner-background, -40%);
      -fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
    }
    
    .priorityMedium { 
      -fx-control-inner-background: skyblue;
      -fx-accent: derive(-fx-control-inner-background, -40%);
      -fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
    }
    
    .priorityHigh { 
      -fx-control-inner-background: palevioletred;
      -fx-accent: derive(-fx-control-inner-background, -40%);
      -fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
    }
    

    rowhighlight


    Detailed styling information for JavaFX can be found in the default caspian.css stylesheet for JavaFX 2.2 and the JavaFX 2 CSS reference guide. To find caspian.css for your version of JavaFX you can unjar jfxrt.jar (sometimes found in the jre/lib directory).

    Update

    The default stylesheet for JavaFX is now named modena.css rather than caspian.css.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I need to create a WP site which will have multiple subjects. Each subject
I need to create a JNLP file for a online Application i have developed
I'm new to Java and JavaFX I have php,javascript,HTML experience... I'm trying to create
i need to create a object Image from import javax.microedition.lcdui.Image; using a file .png
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.