java - TextFlow in TableCell has an extra height -
i tried display rich texts in cells of tableview, , created own subclass of tablecell , set textflow object graphic. textflow has height (textflow in right column): why happen?
the code following (i wrote in groovy same in java):
public class contentcell extends tablecell<word, wordcontent> { protected void updateitem(wordcontent wordcontent, boolean isempty) { super.updateitem(wordcontent, isempty) if (isempty || wordcontent == null) { settext(null) setgraphic(null) } else { textflow textflow = wordcontent.getcontenttextflow() settext(null) setgraphic(textflow) } } } public class dictionarycontroller implements initializable { @fxml private tableview<word> wordtableview @fxml private tablecolumn<word, string> namecolumn @fxml private tablecolumn<word, wordcontent> contentcolumn public void initialize(url location, resourcebundle resources) { contentcolumn.setcellfactory() { tablecolumn<word, wordcontent> column -> return new contentcell() } (int : 0 ..< 50) { wordcontent wordcontent = new wordcontent("test") word word = new word("test" + i.tostring(), wordcontent) wordtableview.getitems().add(word) } } } public class wordcontent { private textflow contenttextflow = new textflow() public wordcontent(string content) { createcontenttextflow(content) } private void createcontenttextflow(string content) { text contenttext = new text(content) contenttextflow.getchildren().addall(contenttext) } public textflow getcontenttextflow() { return contenttextflow } } public class word { private stringproperty name = new simplestringproperty() private objectproperty<wordcontent> content = new simpleobjectproperty() public word(string name, wordcontent content) { this.name.set(name) this.content.set(content) } public stringproperty nameproperty() { return name } public objectproperty<wordcontent> contentproperty() { return content } }
i don't know why column height not calculate correctly? can resolve problem if replace textflow
flowpane
.
if want wrap text, must replace code
private void createcontenttextflow(string content) { text contenttext = new text(content) contenttextflow.getchildren().addall(contenttext) }
by
private void createcontenttextflow(string content) { text contenttext = new text(content) contenttext.wrappingwidthproperty().bind(#your_column_object#.widthproperty().subtract(5)) contenttextflow.getchildren().addall(contenttext) }
Comments
Post a Comment