JavaFX Scene builder: how to display empty rows in table view? how to set style for a TableColumn name in tableview?

StackOverflow https://stackoverflow.com/questions/19424286

I am using javaFX Scene Builder to create a tableview. Requirement is table should show 2 empty rows, allowing user to fill data. But its showing "No conetent in table". How to add empty rows to table? First column in the table is editable and it is a required field. I need to show the first column name in red color, which indicates that it is a required field.How to set color for text?

有帮助吗?

解决方案

I need to show the first column name in red color, which indicates that it is a required field.How to set color for text?

Use css.

File redhead.css

.redhead #colx .label {
    -fx-font-size: 1.2em;
    -fx-font-weight: bold;
    -fx-text-fill: mediumvioletred;
    -fx-background-color: linear-gradient(to bottom, azure, mediumturquoise);
}

tableheader customization

Sample FXML

<?xml version="1.0" encoding="UTF-8"?>

<?scenebuilder-stylesheet redhead.css?>

<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="139.99990000000253" prefWidth="309.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
  <children>
    <TableView layoutX="25.0" layoutY="24.0" prefHeight="93.0" prefWidth="250.0" styleClass="redhead">
      <columns>
        <TableColumn id="colx" maxWidth="5000.0" minWidth="10.0" prefWidth="158.0" style="" styleClass="redhead" text="Column X" />
        <TableColumn prefWidth="75.0" text="Column Y" />
      </columns>
    </TableView>
  </children>
</AnchorPane>

Requirement is table should show 2 empty rows, allowing user to fill data. But its showing "No conetent in table". How to add empty rows to table?

This is somewhat similar to How can I bypass the JavaFX's TableView "placeholder"? (which currently has no accepted answer).

There is an existing feature request in the JavaFX issue tracker: RT-31086 Don't force me to use the default 'placeholder' in an empty TableView.

Ask a new question. Include information on how your new question differs from the existing question, code for what you have tried so far and info on where you are experiencing difficulties.


If your table only has ever has two editable rows in it, a GridPane with Labels for headers and TextFields for edits is probably a better combination of layout and controls to use to implement your functionality than a TableView.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top