Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: (Solved) JavaFX 20 TableView Styling

  1. #1
    Junior Member
    Join Date
    Apr 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default (Solved) JavaFX 20 TableView Styling

    I have a pre-defined TableView control in my app made with SceneBuilder 16. The table displays fine and I have data displaying from my database.

    The problem comes when I wish to provide dynamic styling by programmatically creating the stylesheet on the fly. It works fine for labels where you can set the properties directly. But my attempts to style header and table row cells have fallen flat.

    I create a CSS string from values read in a settings file but shown as constants here:
    String tblCSS = "#tblLogView .column-header .label \n";
    String hdr_font_family = "Inconsolata";
    tblCSS += "{\n";
    tblCSS += " -fx-font-family: '";
    tblCSS += hdr_font_family;
    tblCSS += "';\n";
    tblCSS += " -fx-font-size: ";
    tblCSS += Double.toString(hdr_font_size);
    tblCSS += ";\n";
    tblCSS += "}\n\n";
    tblCSS += "#tblLogView .table-row-cell { -fx-font-family: 'DejaVu Serif'; -fx-font-size: 16.0pt; }

    tblLogView.setStyle(tblCSS);

    The column header labels do change but it makes all rows the same font and size. Changing the .table-row-cell does not change the row content.

    What am I doing wrong?

    Update:
    I have found a workaround that may be useful.
    I write my intended CSS with the dynamic content to a file I call dynamic.css. Then add that to the scene. This seems to work fine.
    Not sure if this is the right way to go about it, but it works and that is what is important now.
    Last edited by AD5XJ; April 28th, 2023 at 07:48 AM.

Similar Threads

  1. Input data directly in Tableview
    By bodylojohn in forum JavaFX
    Replies: 2
    Last Post: September 30th, 2021, 05:27 AM
  2. Replies: 0
    Last Post: June 17th, 2021, 02:40 PM
  3. Copy from TableView list
    By almir97 in forum JavaFX
    Replies: 3
    Last Post: March 3rd, 2021, 01:06 PM
  4. Tableview custom button not responding
    By okimait in forum Computer Support
    Replies: 1
    Last Post: October 7th, 2020, 08:16 AM
  5. JavaFX
    By bodylojohn in forum JavaFX
    Replies: 2
    Last Post: October 16th, 2017, 04:06 AM

Tags for this Thread