This discussion is archived
4 Replies Latest reply: Dec 10, 2012 2:47 AM by eno g. - oracle RSS

TableView Row Height constraint

888909 Newbie
Currently Being Moderated
Currently each row in table view stretches it's height to fit the largest item in the row.
Is there a way to force a constraint on this height so it doesn't get out of hand for large content?

I want it to act like old JTAble and just do a "..." when the content gets too long.
  • 1. Re: TableView Row Height constraint
    eno g. - oracle Newbie
    Currently Being Moderated
    Running into the same issue... one of the cells in the row has multiline text (not a wrapped line)
  • 2. Re: TableView Row Height constraint
    jsmith Guru
    Currently Being Moderated
    Try using cellfactories on the table columns and setting a maxHeight for the returned cells.
  • 3. Re: TableView Row Height constraint
    eno g. - oracle Newbie
    Currently Being Moderated
    I tried to add a cell factory and setMaxHeight but that doesn't seem to work. Row Height prints as 0.0. There was a suggestion at some point to remove the NEWLINE separators, but some of these lines represent stack traces... no good to try and read that in one single line.
    This is how I've tried to implement the cellfactory. Not sure if I'm doing something wrong

    TIA
    private TableColumn<Message, String> createColumn(final int columnIndex, IColumn _currentColumn) 
         {
              TableColumn<Message, String> column = new TableColumn<Message, String>(_currentColumn.getName());
              column.setPrefWidth(150.0);
              column.setCellFactory(new Callback<TableColumn<Message,String>, TableCell<Message,String>> () {
                   @Override
                   public TableCell<Message,String> call(TableColumn<Message,String> param) {
                        return new TableCell<Message, String>() {
                             @Override
                             public void updateItem(String item, boolean empty) {
                                  super.updateItem(item, empty);
                                  setMaxHeight(15.0);
                                  setHeight(15.0);
                                  setText(item);
                             }
                        };
                   }
              });
    Edited by: Eno G. on Dec 9, 2012 9:17 PM
  • 4. Re: TableView Row Height constraint
    eno g. - oracle Newbie
    Currently Being Moderated
    OK I think I'm going with the following... display the first 2 lines of the multiline message and show the whole message in a tooltip.


    public TableCell<Message,String> call(TableColumn<Message,String> param) {
         return new TableCell<Message, String>() {
              @Override
              public void updateItem(String item, boolean empty) {
                   super.updateItem(item, empty);
                   if(item.contains(System.lineSeparator()))
                   {
                        //Get the first 2 lines and the rest of the message
                        String[] displayItem = item.split(System.lineSeparator(), 3);
                        //Display only the first 2 lines of the multiline text
                        setText(displayItem[0] + " " + displayItem[1]);
                   } else {
                        setText(item);
                   }
                   setTooltip(new Tooltip(item));
              }
         };
    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points