1

I have a treetable and I want to set all seen items (focused with mouse) font-weight:normal instead of bold.

But I dont get the treetablerow to archive that. So I need a method which returns the selected treetablerow like the following:

getSelectedTreeTableRow().setStyle("-fx-font-weight: normal;");

The code I've written already is the following but it doesn't work anyway.

    TreeTableView.TreeTableViewSelectionModel selectionModel = m_treeTableMaster.getTreeTableView().getSelectionModel();
    ObservableList selectedCells = selectionModel.getSelectedCells();
    TreeTablePosition tablePosition = (TreeTablePosition) selectedCells.get(0);
    tablePosition.getTableColumn().setStyle("-fx-font-weight: normal;");

I set the rows bold in a cellstyler class when the table is initialized:

m_treeTableMaster.setCellStyler(new ICellStyler()
    {

        @Override
        public void OnStyleCell(MyTableCell p_cell, Object item, boolean empty)
        {
            boolean unseen = codeToDecideIfUnseen();

            if(unseen)
                p_cell.getTreeTableRow().setStyle("-fx-font-weight:bold");
            else
                p_cell.getTreeTableRow().setStyle("-fx-font weight:normal");

In addition:

public class MyTableCell extends TreeTableCell
Thomas Z.
  • 566
  • 6
  • 21
  • why don't you use the same method but with a Selection listener ? – Bo Halim Dec 12 '16 at 13:04
  • It doesnt effect the result I think – Thomas Z. Dec 12 '16 at 13:17
  • 1
    Did you try with a css selector? Something like `table-cell:selected`? – Itai Dec 12 '16 at 13:39
  • By the way - in the default style (Modena), selected TreeTableView rows aren't in bold. If yours are, maybe you should look at where you defined them to be bold in the first place. – Itai Dec 12 '16 at 13:49
  • In my stylecell renderer I defined that they are bold, when unread. But the problem is that I cannt change it on the "live" system – Thomas Z. Dec 12 '16 at 13:56
  • Please include the method/code you use to set them to bold - it is probably related. – Itai Dec 12 '16 at 13:57
  • When is `OnStyleCell` called? How is the logic that determines `unseen` is defined? The most probable answer is that you re-style it through your cell styler, but since your implementation is non-standard it would be quite hard to tell without an [MCVE](http://stackoverflow.com/help/mcve). More to the point - I would suggest that you take advantage of Pseudo Classes to define how seen and unseen cells are rendered. See for example [this answer](http://stackoverflow.com/questions/36883838/implement-read-only-style-in-javafx/36886291#36886291). – Itai Dec 12 '16 at 14:39

0 Answers0