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 6673361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:37:07+00:00 2026-05-26T03:37:07+00:00

In my Java Desktop Application I have a JavaFX Table with 3 columns. I

  • 0

In my Java Desktop Application I have a JavaFX Table with 3 columns. I want to set the font color of the 3rd column to red. I have not been able to set the font color of the Tableb at all. I looked into CSS and I did not find anything. Is there a way to do it with CSS? I also looked for setFont() with the hope of setting it that way. Nothing there. I could not even figure a way to set something on a certain cell.

TableView<TableData> myTable = new TableView<TableData>();
ObservableList<TableData> myTableData = FXCollections.observableArreyList(
    new TableData("data", "data", "data"),
    new TableData("data", "data", "data"));

TableColumn firstColumn = new TableColumn("First Column");
firstColumn.setProperty("one");
TableColumn secondColumn = new TableColumn("Second Column");
secondColumn .setProperty("two");
TableColumn thirdColumn = new TableColumn("Third Column");
thirdColumn .setProperty("three");

myTable.setItems(myTableData);
myTable.getColumns.addAll(firstColumn, secondColumn, thirdColumn);

How can I accomplish this? How can I set to font color? Any help will be appreciated.

  • 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-05-26T03:37:08+00:00Added an answer on May 26, 2026 at 3:37 am

    You need to override the CellFactory.

    Partial code just of the third column:

        TableColumn thirdColumn = new TableColumn("Third Column");  
        thirdColumn.setCellValueFactory(new PropertyValueFactory<TableData,String>("three"));
    
        // ** The TableCell class has the method setTextFill(Paint p) that you 
        // ** need to override the text color
        //   To obtain the TableCell we need to replace the Default CellFactory 
        //   with one that returns a new TableCell instance, 
        //   and @Override the updateItem(String item, boolean empty) method.
        //
        thirdColumn.setCellFactory(new Callback<TableColumn, TableCell>() {
            public TableCell call(TableColumn param) {
                return new TableCell<TableData, String>() {
    
                    @Override
                    public void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (!isEmpty()) {
                            this.setTextFill(Color.RED);
                            // Get fancy and change color based on data
                            if(item.contains("@")) 
                                this.setTextFill(Color.BLUEVIOLET);
                            setText(item);
                        }
                    }
                };
            }
        });
    

    Entire Code Example:

    package tablecelltextcolorexample;
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.scene.Scene;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.Priority;
    import javafx.scene.layout.VBox;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    
    /**
     *
     * @author jKaufmann
     */
    public class TableCellTextColorExample extends Application {
    public static class TableData {
        SimpleStringProperty one,two,three;
        public TableData(String one, String two, String three) {
            this.one = new SimpleStringProperty(one);
            this.two = new SimpleStringProperty(two);
            this.three = new SimpleStringProperty(three);
        }
        public String getOne() {
            return one.get();
        }
    
        public void setOne(String one) {
            this.one.set(one);
        }
    
        public String getThree() {
            return three.get();
        }
    
        public void setThree(String three) {
            this.three.set(three);
        }
    
        public String getTwo() {
            return two.get();
        }
    
        public void setTwo(String two) {
            this.two.set(two);
        }
    
    } 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Application.launch(args);
    }
    
    @Override
    public void start(Stage stage) {
        VBox vbox = new VBox();
        Scene scene = new Scene(vbox, 200, 200);
        stage.setTitle("Table View - Change color of a particular column");
        stage.setWidth(400);
        stage.setHeight(500);
    
    
        TableView<TableData> myTable = new TableView<TableData>();
        ObservableList<TableData> myTableData = FXCollections.observableArrayList(
                new TableData("data", "data", "data"),
                new TableData("data", "data", "data"),
                new TableData("Name the song","867-5309","SomeEmail@gmail.com"));  
    
        TableColumn firstColumn = new TableColumn("First Column"); 
        firstColumn.setCellValueFactory(new PropertyValueFactory<TableData,String>("one"));
    
        TableColumn secondColumn = new TableColumn("Second Column"); 
        secondColumn.setCellValueFactory(new PropertyValueFactory<TableData,String>("two"));
    
        TableColumn thirdColumn = new TableColumn("Third Column");  
        thirdColumn.setCellValueFactory(new PropertyValueFactory<TableData,String>("three"));
    
        // ** The TableCell class has the method setTextFill(Paint p) that you 
        // ** need to override the text color
        //   To obtain the TableCell we need to replace the Default CellFactory 
        //   with one that returns a new TableCell instance, 
        //   and @Override the updateItem(String item, boolean empty) method.
        //
        thirdColumn.setCellFactory(new Callback<TableColumn, TableCell>() {
            public TableCell call(TableColumn param) {
                return new TableCell<TableData, String>() {
    
                    @Override
                    public void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (!isEmpty()) {
                            this.setTextFill(Color.RED);
                            // Get fancy and change color based on data
                            if(item.contains("@")) 
                                this.setTextFill(Color.BLUEVIOLET);
                            setText(item);
                        }
                    }
                };
            }
        });
    
        myTable.setItems(myTableData); 
        myTable.getColumns().addAll(firstColumn, secondColumn, thirdColumn);
    
        vbox.getChildren().addAll(myTable);
        VBox.setVgrow(myTable, Priority.ALWAYS);
    
        stage.setScene(scene);
        stage.show();
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails server, and I want my Java desktop application & android
In my Java Desktop Application I have a TableView in which I want to
I have created a Java desktop application and I want to run it from
I have Java desktop application that works with CSV files. And i want add
I am developing a Java Desktop Application but have some confusions in choosing a
I have an Java desktop application which connects directly with the DB (an Oracle).
I have a java desktop application with information about several entities. There is a
I am developing a Java desktop application and would like to have an external
I have a large tree of Java Objects in my Desktop Application and am
I am developing a Java Desktop Application and want a light database that can

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.