在SceneBuilder中包装单元格文本

时间:2018-07-25 11:06:37

标签: java fxml scenebuilder

我正在尝试在TableView单元格中制作长文本以进行换行,而不是创建省略号并像下面所示将文本剪掉。

Unwanted result

下面是我的java和fxml代码。如何将文本包装在单元格中?

JAVA代码

public class Articles implements Initializable{
@FXML TableView<ArticlesModel> HomeTable;
@FXML JFXTextField Searchbar;
@FXML JFXButton SearchButton;
@FXML
public void searchCompany(){
    refreshTable(Searchbar.getText());
}
@Override
public void initialize(URL location, ResourceBundle resources) {
    HomeTable.setEditable(true);
    HomeTable.getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("ID"));
    HomeTable.getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("Company"));
    HomeTable.getColumns().get(2).setCellValueFactory(new PropertyValueFactory<>("CompanyN"));
    HomeTable.getColumns().get(3).setCellValueFactory(new PropertyValueFactory<>("ArticleTitle"));
    HomeTable.getColumns().get(4).setCellValueFactory(new PropertyValueFactory<>("ArticleDate"));
    HomeTable.getColumns().get(5).setCellValueFactory(new PropertyValueFactory<>("ArticleText"));
    refreshTable("");
}
private void refreshTable(String search){
    HomeTable.getItems().clear();
    String sql = "SELECT * FROM info";
    ConnectDatabase connection = new ConnectDatabase();
    if(!search.trim().equals("")){
        sql = "SELECT * FROM info WHERE UPPER(CompName) LIKE UPPER('%"+ search +"%')";
        System.out.println(sql);
    }
    try (Connection conn = connection.connect(); Statement stmt  = conn.createStatement(); ResultSet rs    = stmt.executeQuery(sql)) {
        while (rs.next()) {
            int ID = rs.getInt(1);
            String Company = rs.getString(2);
            String CompanyN = rs.getString(3);
            String ArticleTitle = rs.getString(4);
            Date ArticleDate = rs.getDate(5);
            String ArticleText = rs.getString(6);
            ArticlesModel model = new ArticlesModel(ID, Company, CompanyN, ArticleTitle, ArticleDate, ArticleText);
            HomeTable.getItems().add(model);
        }
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
}

}

FXML代码

<AnchorPane prefHeight="768.0" prefWidth="1366.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.Articles.Articles">
<children>
    <StackPane layoutX="35.0" layoutY="88.0" prefHeight="618.0" prefWidth="1046.0" AnchorPane.bottomAnchor="35.0" AnchorPane.leftAnchor="35.0" AnchorPane.rightAnchor="35.0" AnchorPane.topAnchor="115.0">
        <children>
            <TableView fx:id="HomeTable" prefHeight="200.0" prefWidth="200.0">
                <columns>
                    <TableColumn fx:id="ID" editable="false" minWidth="5.0" prefWidth="75.0" text="ID" />
                    <TableColumn fx:id="CompanyName" minWidth="5.0" prefWidth="200.0" text="Company" />
                    <TableColumn fx:id="CompanyNDG" minWidth="5.0" prefWidth="100.0" text="Company N" />
                    <TableColumn fx:id="ArticleTitle" minWidth="5.0" prefWidth="200.0" text="Article Title" />
                    <TableColumn fx:id="ArticleDate" minWidth="5.0" prefWidth="150.0" text="Article Date" />
                    <TableColumn fx:id="ArticleText" minWidth="5.0" prefWidth="320.0" text="Article Text" />
                </columns>
            </TableView>
        </children></StackPane>
    </children></AnchorPane>
</children>

0 个答案:

没有答案