TableView

Hello)

I tried to create a TableView in my application and use the example

http://docs.BlackBerry.com/en/developers/deliverables/18125/Table_Model_1328111_11.jsp

I copy this code in my main class and Exchange image filename "icon png", but it crashes after running.

Could you help me? Becose I have now what I am doing wrong...

I would say to set the column property, then.
I suppose that you added another column, but don't forget to add this line:
dataTemplate.setColumnProperties (0, TemplateColumnProperties (width));
(sample, change it to your column, of course)

Tags: BlackBerry Developers

Similar Questions

  • TableView with FocusChangeListener question field

    I created a TableView and adds items.  On one point, I use a FocusChangeListener to get the read line for action.

    It works for OS 7, especially because the simulator (9900) has a touch screen.  However, in an OS 6 non touch screen simulator (9650), the FocusChangeListener is not currently enabled.  Any item is moved to the update, it only selects the first.

    I don't know if there is a place more to put the FocusChange.  I need to know which item is currently focused on, to the next screen or to place an order on this point.  I also wonder if the pill buttons are causing a problem with the TableView.

    Here is a screenshot.

    Here is the part that creates the TableView

    // Create Table items
                    soTableModel = new TableModel();
                    soTableView = new TableView(soTableModel);
                    soTableController = new TableController(soTableModel, soTableView, TableController.ROW_FOCUS);
                    soTableView.setDataTemplateFocus(BackgroundFactory.createSolidTransparentBackground(Color.BLUE, 105));
                    soTableView.setController(soTableController);
                    // Create temporary Date holder and Formatter
                    Date tmpDate;
                    SimpleDateFormat shortFormat = new SimpleDateFormat(SimpleDateFormat.DATE_DEFAULT);
                    shortFormat.applyPattern("MMM-dd H:mm a");
    
                    // Add Tables items
                    soCursor = ServiceOrderHeader.getServiceOrders(ServiceOrderType, ServiceOrderSortBy);
                    while(soCursor.next())
                    {
                        Row tmpRow = soCursor.getRow();
                        // Get Date and Format it
                        tmpDate = new Date(tmpRow.getLong(ServiceOrderHeader.REQ_START_DATETIME));
                        // Get Service Order ID
                        String tmpServiceOrderID = tmpRow.getString(ServiceOrderHeader.SERVICEORDERID);
                        if(soCursor.getPosition() == 0){
                            SelectedServiceOrder = tmpServiceOrderID;
                        }
    
                        // Get Site Name and check to see if it is longer than 30 characters, if so, truncate it
                        String finalSiteName = tmpRow.getString(ServiceOrderHeader.SITE_NAME);
                        if(finalSiteName.length() > 30){
                            finalSiteName = finalSiteName.substring(0, 27) + "...";
                        }
    
                        String tmpProduct = CodeSet.getValueByListKey("Service Order Product", "Service Order Product Restrict", tmpRow.getString(ServiceOrderHeader.SERVICE_PRODUCT), CodeSet.orderByKey);
                        if(tmpProduct.indexOf("Preventive") > 0) {
                            tmpProduct = "PM";
                        }
    
                        //Add the Strings to the table.
                        soTableModel.addRow(new Object[]
                               { ServiceOrderHeader.newStatus(tmpRow.getString(ServiceOrderHeader.SERVICEORDERID)),
                                ServiceOrderHeader.dirtyStatus(tmpRow.getString(ServiceOrderHeader.SERVICEORDERID)),
                                ErrorLog.hasError(tmpServiceOrderID),
                                tmpServiceOrderID,
                                tmpProduct,
                                tmpRow.getString(ServiceOrderHeader.SO_STATUS),
                                shortFormat.format(tmpDate).toString(),
                                Integer.toString(tmpRow.getInteger(ServiceOrderHeader.IBASE)),
                                Integer.toString(tmpRow.getInteger(ServiceOrderHeader.SITE_BP_NR)),
                                finalSiteName
                                }, false);
                    }
    
                    // Set the Table Style
                    setStyle(soTableView, 3, 4);
    
                    // add table to content display
                    soContent.add(soTableView);
    

    I put the FocusChangeListener on article 3, which is the field ID so.

      public static void setStyle(DataView tableView, int rows, int columns)
        {
            DataTemplate soDataTemplate = new DataTemplate(tableView, rows, columns)
            {
                /**
                 * @see DataTemplate#getDataFields(int)
                 */
                public Field[] getDataFields(int modelRowIndex)
                {
                    TableModel theModel = (TableModel) getView().getModel();
                    Object[] data = (Object[]) theModel.getRow(modelRowIndex);
                    Field[] fields = new Field[data.length];
                    for(int i = 0; i < data.length; i++)
                    {
                        if(data[i] instanceof Bitmap)
                        {
                            fields[i] = new BitmapField((Bitmap) data[i]);
                        }
                        else if(data[i] instanceof String)
                        {
                            switch(i){
                                case 3:
                                    fields[i] = new bhHeaderField(String.valueOf(data[i]), Field.FOCUSABLE, Color.BLACK, Color.WHITE);
                                    fields[i].setFocusListener(serviceOrderFocusListener);
                                    break;
                                case 5:
                                    fields[i] = new bhHeaderField(String.valueOf(data[i]), Field.NON_FOCUSABLE, Color.WHITE, Color.RED);
                                    break;
                                case 6:
                                    fields[i] = new bhHeaderField(String.valueOf(data[i]), Field.NON_FOCUSABLE, Color.WHITE, CustomUi.bhColor);
                                    break;
                                default:
                                    fields[i] = new LabelField(data[i], LabelField.NON_FOCUSABLE);
                                    break;
                            }
                        }
                        else
                        {
                            fields[i] = (Field) data[i];
                        }
                    }
    
                    return fields;
                }
            };
            // Create Image Width and Height, since image is a square
            int imgWidthHeight = appAttributes.IMAGE_WIDTH
                + (CustomUi.cellStyle.getBorder() == null ? 0 : CustomUi.cellStyle.getBorder().getTop()
                + CustomUi.cellStyle.getBorder().getBottom()) + (CustomUi.cellStyle.getMargin() == null ? 0 : CustomUi.cellStyle.getMargin().top
                + CustomUi.cellStyle.getMargin().bottom);
            // Create Row settings
            // First Row
            soDataTemplate.setRowProperties(0, new TemplateRowProperties(Font.getDefault().getHeight() +
                    (CustomUi.cellStyle.getBorder() == null ? 0 : CustomUi.cellStyle.getBorder().getTop() + CustomUi.cellStyle.getBorder().getBottom()) +
                    (CustomUi.cellStyle.getMargin() == null ? 0 : CustomUi.cellStyle.getMargin().top + CustomUi.cellStyle.getMargin().bottom)));
            // Second Row
            soDataTemplate.setRowProperties(1, new TemplateRowProperties(Font.getDefault().getHeight() +
                    (CustomUi.cellStyle.getBorder() == null ? 0 : CustomUi.cellStyle.getBorder().getTop() + CustomUi.cellStyle.getBorder().getBottom()) +
                    (CustomUi.cellStyle.getMargin() == null ? 0 : CustomUi.cellStyle.getMargin().top + CustomUi.cellStyle.getMargin().bottom)));
            // Third Row
            soDataTemplate.setRowProperties(2, new TemplateRowProperties(Font.getDefault().getHeight() +
                    (CustomUi.cellStyle.getBorder() == null ? 0 : CustomUi.cellStyle.getBorder().getTop() + CustomUi.cellStyle.getBorder().getBottom()) +
                    (CustomUi.cellStyle.getMargin() == null ? 0 : CustomUi.cellStyle.getMargin().top + CustomUi.cellStyle.getMargin().bottom)));
            // Create Column Settings
            // First Column
            soDataTemplate.setColumnProperties(0, new TemplateColumnProperties((int) Math.floor(imgWidthHeight)));
            // Second Column
            soDataTemplate.setColumnProperties(1, new TemplateColumnProperties((int) Math.floor((Display.getWidth() - imgWidthHeight) * .25)));
            // Third Column
            soDataTemplate.setColumnProperties(2, new TemplateColumnProperties((int) Math.floor((Display.getWidth() - imgWidthHeight) * .45)));
            // Fourth Column
            soDataTemplate.setColumnProperties(3, new TemplateColumnProperties((int) Math.floor((Display.getWidth() - imgWidthHeight) * .30)));
    
            // Add Region (cell) properties
            // First Image Cell, expands columns 1 and row 1
            soDataTemplate.createRegion(new XYRect(0, 0, 1, 1), CustomUi.cellStyle);
            // Second Image Cell, expands columns 1 and row 2
            soDataTemplate.createRegion(new XYRect(0, 1, 1, 1), CustomUi.cellStyle);
            // Third Image Cell, expands columns 1 and row 3
            soDataTemplate.createRegion(new XYRect(0, 2, 1, 1), CustomUi.cellStyle);
    
            // First Data Cell, expands columns 2,3,4 and row 1
            soDataTemplate.createRegion(new XYRect(1, 0, 3, 1), CustomUi.cellStyle);
            // Second Data Cell, expands column 4 and row 1
            soDataTemplate.createRegion(new XYRect(3, 0, 1, 1), CustomUi.cellStyle);
            // Third Data Cell, expands column 1 and row 2
            soDataTemplate.createRegion(new XYRect(1, 1, 1, 1), CustomUi.cellStyle);
            // Fourth Data Cell, expands column 2 and row 2
            soDataTemplate.createRegion(new XYRect(2, 1, 1, 1), CustomUi.cellStyle);
            // Fifth Data Cell, expands column 3 and row 2
            soDataTemplate.createRegion(new XYRect(3, 1, 1, 1), CustomUi.cellStyle);
            // Sixth Data Cell, expands column 1 and row 3
            soDataTemplate.createRegion(new XYRect(1, 2, 1, 1), CustomUi.cellStyle);
            // Seventh Data Cell, expands column 2,3 and row 3
            soDataTemplate.createRegion(new XYRect(2, 2, 2, 1), CustomUi.cellStyle);
    
            //Apply the template to the view
            soDataTemplate.useFixedHeight(true);
            soTableView.setDataTemplate(soDataTemplate);
        }
    

    And here's the FocusChangeListener

       private static class ServiceOrderFocusListener implements FocusChangeListener
        {
            public void focusChanged(Field field, int eventType) {
                if(eventType == FOCUS_GAINED){
                    if(field.isFocusable()) {
                        SelectedServiceOrder = field.toString();
                        appAttributes.isEditableSO = ServiceOrderHeader.isEditable(SelectedServiceOrder);
                        Dialog.inform("Selected Service Order : " + SelectedServiceOrder);
                        System.out.println("Selected Service Order : " + SelectedServiceOrder);
                    }
                }
            }
        }
        static ServiceOrderFocusListener serviceOrderFocusListener = new ServiceOrderFocusListener();
    

    I found TableView.getRowNumberWithFocus ();

    So, instead of putting a FocusChangeListener on this point, I just get the current line being focused on the table.  The, I call the data slider and set the position; Cursor.position (CurrentRow);  to get the straight line of the cursor in order to obtain the appropriate data.

    Here is an example that is called when the button to find the information of the inventory for the part.  I get the current line, get the same data as that used to fill in the data.  Place the cursor to the selected position and retrieve columns that I have to go down on my request.

    int currentRow = resultsTableView.getRowNumberWithFocus();
                     try {
                         Cursor partResults = PartSearch.getPartSearch(CurrentOrderBy, CurrentRowLimit, CurrentRowOffset);
                         partResults.position(currentRow);
                         Row thisRow = partResults.getRow();
                         CurrentSAPNumber = thisRow.getString(PartSearch.SAP_PART_NUMBER);
                         CurrentPartName = thisRow.getString(PartSearch.PART_NAME);
    
                     } catch (DatabaseException dbe) {
                         SDApp.handleException(dbe, "Search Inventory Command(dbe)");
                     } catch (DataTypeException dte) {
                         SDApp.handleException(dte, "Search Inventory Command(dbe)");
                    }
    
  • TableView DataTemplate curious behavior of line height

    I noticed a problem of calculation of the HEIGHT of the LINE of the rows of the Table in a TableView.

    as a first step, I put TemplateRowProperties (40, PIXEL_HEIGHT).

    tested with some lines and it worked.

    But if there are more lines height becomes higher as more lines are there.

    has then tried to replace PERCENTAGE_HEIGHT and the value 10, so I expected that each line should get 10% of the display height.

    but the behavior even if there are more lines.

    Finally I'm done with this workaround: (not perfect, but in my case there are between 2 and 50 ranks works)

    dataTemplate.useFixedHeight(true);
    
    // Define regions and row height
    for (int i = 0; i < ROW_COUNT; i++) {
       dataTemplate.setRowProperties(i, new TemplateRowProperties(
           Math.max(1, MathUtilities.round(50/ROW_COUNT)),
                TemplateRowProperties.PERCENTAGE_HEIGHT));
    }
    

    is this a known bug? or I did something wrong?

    tried to useFixedHeight the value false, but then the height was too small.

    It's a simple table with 3 columns. Column width properties work as expected.

    int[]columnWidthPercent = new int[]{10,25,65};
    for(int col = 0; col < COL_COUNT; col++) {
          dataTemplate.createRegion(new XYRect(col,0,1,1));
          dataTemplate.setPosition(col,0,14);
          dataTemplate.setColumnProperties(
            col,
            new TemplateColumnProperties(
              columnWidthPercent[col],
              TemplateColumnProperties.PERCENTAGE_WIDTH));
    }
    

    THX

    We have problems with our login server Thursday, which have been resolved.

    Thanks for the taping of the show.  Someone should look into it soon.

  • Can I use Listview as static tableview in Xcode?

    Can I use Listview as static tableview in Xcode?

    Sure! You can load an XML data

    Just check the list tutorial (http://developer.blackberry.com/cascades/documentation/ui/lists/lists_set_up_project.html)

  • Cannot add TableView to VerticalFieldManager

    My problem is that if one create a value for money, I can add fields to the optimization of resources, but if I take a tableview which works perfectly without the optimization of resources and add it to the optimization of the vfm resources I'll always get an exception IllegalState is it a limitation which does not allow me to add a tableview for optimization of resources?

    So now that I've found the problem, I run remote debugging and I see that the system reports:

    "Tables must be added to a scrolling no Manager.

    So it seems to be a limitation, and I can assure you that if I put the vfm as VERTICAL_SCROLL then I get the error but if I put it at NO_VERTICAL_SCROLL, it works fine.

    Thanks to all who responded.

  • How to use and add a tableview?

    As mentioned on the subject.

    Can someone teach me how to add a tableview in qml? My goal is just to make a tableview with 100% width and height with 2 columns and each column with buttons with the width and height of 100%. How can I achieve that?

    Thank you.

    You can use a battery with quotas of space available:

        Container {
            id: tableViewContainer
            layout: StackLayout {
                orientation: LayoutOrientation.LeftToRight
            }
            horizontalAlignment: HorizontalAlignment.Fill
            Container {
                id: leftColumnContainer
                background: Color.create("#00ff00")
                horizontalAlignment: HorizontalAlignment.Fill
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 0.5
                }
                Label {
                    text: "left"
                    horizontalAlignment: HorizontalAlignment.Center
                }
            }
            Container {
                id: rightColumnContainer
                background: Color.create("#ff0000")
                horizontalAlignment: HorizontalAlignment.Fill
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 0.5
    
                }
                Label {
                    text: "right"
                    horizontalAlignment: HorizontalAlignment.Center
                }
            }
        }
    
  • Creating a TableView with a component, problem with my lines.

    I am trying to create a table in a pane. Each row in the table will have three columns. I found an example of code to create the table, but I'm getting additional lines that I don't want.

    I want only lines with 3 columns but I have extra lines, including the content of the last column see image.

    Is someone can you please tell me what is wrong with my code?

        private Pane createPane(String category) {
    
            VerticalFieldManager vfm = new VerticalFieldManager();
    
            vfm.add(new LabelField("Add Task:", Field.FOCUSABLE | LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));
    
            // Initialize the model if it has not yet been loaded
            _tableModel = new SortedTableModel(StringComparator.getInstance(true), 2);
    
            // Populate the list
            for (int i = 0; i < 3; i++) {
    
                String col1 = i + " 1";
                String col2 = i + " 5";
                String col3 = i + " 3";
    
                _tableModel.addRow(new Object[]  {col1, col2, col3});
            }
    
            // Create and apply style
            RegionStyles style = new RegionStyles(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1), Border.STYLE_SOLID), null, null,
                null, RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_TOP);
    
            // Create the view and controller
            TableView tableView = new TableView(_tableModel);
            TableController tableController = new TableController(_tableModel, tableView);
    
            // Set the controller focus policy to highlight rows
            tableController.setFocusPolicy(TableController.ROW_FOCUS);
    
            // Set the behaviour of the controller when a table item is clicked
            tableController.setCommand(new CommandHandler()
            {
                /**
                 * @see CommandHandler#execute(ReadOnlyCommandMetadata, Object)
                 */
                public void execute(ReadOnlyCommandMetadata metadata, Object context)
                {
                    Dialog.alert("Command Executed");
                }
    
            }, null, null);
    
            tableView.setController(tableController);
    
            // Create a DataTemplate that suppresses the third column
            DataTemplate dataTemplate = new DataTemplate(tableView, 1, 3)
            {
                /**
                 * @see DataTemplate#getDataFields(int)
                 */
                public Field[] getDataFields(int modelRowIndex)
                {
                    Object[] data = (Object[]) ((TableModel) getView().getModel()).getRow(modelRowIndex);
    
                    Field[] fields = new Field[3];
                    fields[0] = new LabelField(data[0], Field.FOCUSABLE);
                    fields[1] = new LabelField(data[1], Field.FOCUSABLE | DrawStyle.HCENTER);
                    fields[2] = new LabelField(data[2], Field.FOCUSABLE);
    
                    return fields;
                }
            };
    
            // Set up regions
            dataTemplate.createRegion(new XYRect(0, 0, 1, 1), style);
            dataTemplate.createRegion(new XYRect(1, 0, 1, 1), style);
            dataTemplate.createRegion(new XYRect(2, 0, 1, 1), style);
    
            // Specify the size of each column by percentage, and the height of a row
            dataTemplate.setColumnProperties(0, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH));
            dataTemplate.setColumnProperties(1, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH));
            dataTemplate.setColumnProperties(2, new TemplateColumnProperties(70, TemplateColumnProperties.PERCENTAGE_WIDTH));
            dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));
    
            // Apply the template to the view
            tableView.setDataTemplate(dataTemplate);
            dataTemplate.useFixedHeight(true);
    
            vfm.add(tableView);
    
            // Pane's title
            LabelField iconTextLabelField = new LabelField(category, Field.FOCUSABLE | Field.FIELD_HCENTER);
            return (new Pane(iconTextLabelField, vfm));
        }
    

    Thanks in advance.

     _tableModel = new SortedTableModel(StringComparator.getInstance(true), 2); <-- "2" sorts it by the object at index 2, which is your "col3". The extra rows you see are like headers for the sorting. I think you should use a different Table Model.
    
            // Populate the list
            for (int i = 0; i < 3; i++) {
    
                String col1 = i + " 1";
                String col2 = i + " 5";
                String col3 = i + " 3";
    
                _tableModel.addRow(new Object[]  {col1, col2, col3});
            }
    
  • TableView with dynamic and updatable columns

    Hello!!

    Im trying to encode a TableView with dynamic columns and I saw a lot of examples like this: create columns dynamically

    But none who would work for my needs.

    Its very simple:

    I got a list of customers, and each has a list of purchases.

    A purchase has a string "buyDetail" and a Date for the ship.

    My TableView need the first column with the name of the client, and a column more for each day of existing ships.

    We do not know previously days that will be used.

    If the sum is greater than 100, for example, I need to be able to apply different styles.

    Example:

    Customer 02/01/2015 03/01/2015 09/01/2015
    Morgan$400 (buyDetail)0$100
    Luis00$20
    Steven$1000
    Hulk0$5$32

    I can't use the properties because I don't know how to buy will have to each customer.

    My best test (only for the first column) was next, but I can't buy it updated if I change the value in the cell:

    I did not try to write other code columns because I feel that I don't hurt really...

    This shows the names of Customer´s, but I can't manage if data modification.

    table = new TableView<Customer>();
    ObservableList<Customer> lista = FXCollections.observableList(registros);
    
    table.setItems(lista);
    
    TableColumn<Customer, Customer> customerNameColumn = new TableColumn<Customer, Customer>("");
      customerNameColumn.setCellValueFactory(new Callback<CellDataFeatures<Customer, Customer>, ObservableValue<Customer>>() {
      public ObservableValue<Customer> call(CellDataFeatures<Customer, Customer> p) {
      return new SimpleObjectProperty(p.getValue());
      }
      });
    
      customerNameColumn.setCellFactory(column -> {return new TableCell<Customer, Customer>() {
      @Override
      protected void updateItem(Customer item, boolean empty) {
      super.updateItem(item, empty);
    
      if (item == null || empty) {
      } else {
      setText(item.getName());
      //APPLY STYLE
      }
      }
      };
      });
    
      table.getColumns().addAll(customerNameColumn);
    

    Post edited by: user13425433

    The columns are available already update default... If you happen to use JavaFX properties for the value of the source.

    The core of you're your question lies in your cellValueFactory.

    Here we have only the cellValueFactory for the name, not for the other columns. So I'll take the name for example, and you have to adapt to the other columns.

    But if you do something like this to your cellValueFactory:

    new SimpleObjectProperty(p.getValue().getName());
    

    Then the name can never be updated if it modifies the client instance: there is no "link" between the name and the property used by the table.

    We have therefore 3 test case:

    • If the name is a property of JavaFX and you do something like:
    TableColumn customerNameColumn = new TableColumn("Customer");
    customerNameColumn .setCellValueFactory(new PropertyValueFactory<>("name"));
    

    Then, if the name change pending Customer-> value in the table automatically changes.

    It also works the other way around: If the table is editable, and the name property is not unalterable-> the value of the changes of names in the Customer instance follows the table has been changed.

    • Now, if your name is not a property of JavaFX but a Java Bean observable property instead (this means that you can register and unregister an instance of Java Bean PropertyChangeListener to this property), you can do:
    TableColumn customerNameColumn = new TableColumn("Customer");
    customerNameColumn.setCellValueFactory(new Callback, ObservableValue>() {
        @Override
        public ObservableValue call(TableColumn.CellDataFeatures p) {
            final Customer t = p.getValue();
            try {
                return JavaBeanStringPropertyBuilder.create().bean(t).name("name").build();
            } catch (NoSuchMethodException ex) {
                // Log that.
                return null;
            }
        }
    });
    

    In this way, you have created a JavaFX property that is bound to an observable property Java Bean.

    Same as above, it works both ways when possible.

    • The latter case is that your name is neither a JavaFX property or a Java Bean-> you can not update unless you happen to create a kind of observer/listener that can update the property with the most recent value.

    Something like that:

    TableColumn customerNameColumn = new TableColumn("Customer");
    customerNameColumn.setCellValueFactory(new Callback ObservableValue>() {
      public ObservableValue call(CellDataFeatures p) {
        final Customer t = p.getValue();
        final SimpleStringProperty result = new SimpleStringProperty ();
        result.setvalue(t.getName());
        t.addNameChangeListener(new NameChangeListener() {
          @Override
          public void nameChanged() {
            result.setvalue(t.getName());
          }
        });
        return result;
      }
    });
    

    If you don't do something like that, the value of the table will never change when the name changes in the instance because the table does not change.

    Now, you will need to apply this theory to your price columns. I hope that I was clear enough to help you.

  • TableView context Menu appears when running Java 8 until Update 5 but not later

    The code below works as its name suggests the update of Java 8 5 but not later:

    SerializableAttribute public class TableViewShowingOnlyAnAppendContextMenuItemIfRowIsEmptyElseDeleteIsIncluded extends Application {}

    final table private TableView < name > = new TableView <>();

    private data of ObservableList < name > finals = FXCollections.observableArrayList (new Name("Jacob"),

    New Name("Isabella"), New Name ("Ethan"), Name ("Emma") New Name ("Michael")) new;

    Public Shared Sub main (String [] args) {}

    Launch (args);

    }

    @Override

    {} public void start (steps)

    TableColumn < String > name, column = new TableColumn <>("name");

    column.setCellValueFactory (new PropertyValueFactory <>("name"));

    table.getColumns () .add (column);

    table.setItems (data);

    ContextMenu contextMenu = new ContextMenu();

    contextMenu.getItems () .add (MenuItem ("append")) new;

    table.setContextMenu (contextMenu);

    table.setRowFactory (tableView-> {}

    TableRow < name > line = new <>(TableRow);

    row.contextMenuProperty () .bind ((in English only)

    Bindings.When (Bindings.isNotNull (Row.itemProperty ()))

    . Then (showOnlyAppendContextMenuItemIfRowIsEmptyElseIncludeDelete ())

    .otherwise ((ContextMenu) null));

    next row;

    });

    Scene = new Scene (table);

    stage.setScene (scene);

    internship. Show();

    }

    private ContextMenu showOnlyAppendContextMenuItemIfRowIsEmptyElseIncludeDelete() {}

    RowMenu ContextMenu = new ContextMenu();

    ContextMenu tableMenu = table.getContextMenu ();

    If (tableMenu! = null)

    rowMenu.getItems () .addAll (tableMenu.getItems ());

    rowMenu.getItems () .add (MenuItem ("delete")) new;

    Return rowMenu;

    }

    Public NotInheritable class {name}

    private final SimpleStringProperty name

    private (String name) {}

    myIdName = new SimpleStringProperty (name);

    }

    public String getName() {}

    Return name.get ();

    }

    public void setName (String name) {}

    This.Name.Set (Name);

    }

    }

    }

    Can help me find the error in the code? Or if there is anything, it's a regression which must be submitted? From now on, all computers used have 8u5.

    Thanks in advance.

    Answered correctly by James_D:

    http://StackOverflow.com/questions/28195552/JavaFX-TableView-context-menu-item-shows-up-when-run-on-Java-8-until-Update-5-Bu

    pasted below:

    The solution is to create new menu items which are copies of those in the context menu of the table:

    private ContextMenu showOnlyAppendContextMenuItemIfRowIsEmptyElseIncludeDelete() {}
        RowMenu ContextMenu = new ContextMenu();
        ContextMenu tableMenu = table.getContextMenu ();
        If (tableMenu! = null) {}
            {for (MenuItem item: {tableMenu.getItems ())}
                RowItem MenuItem = new MenuItem (item.getText ());
                rowItem.setGraphic (item.getGraphic ());
                rowItem.setOnAction (item.getOnAction ());
                rowMenu.getItems () .add (rowItem);
            }
        }
        rowMenu.getItems () .add (MenuItem ("delete")) new;
        Return rowMenu;

    }

  • TableView: column widths computed for the contents of the cells and ignorant header

    Hallo,

    I use the tableview component. The header font size is higher then that of the cells. The problem is: the width of the column based on the cell that contains the longest string, and if the header-string has a length, then the header is truncated (it shows the points of suspension) and I need to change the width of column manually. How could I solve this problem? The easiest way would be to calculate the width of column on myself. I can't find any method in javafx, allowing to calculate the width of the string in pixels. Bat there is the FontMetrics class and the Graphics class, so it's easy to get the width in pixels. There pendants to this course in JavaFX?

    regarding

    Rafal Z

    It is indeed a problem valid and I had only a short time consuming solution. You can create a new instance of a few well-chosen javafx.scene.Node and apply the same style you have in your column header. You would then proceed with

    new Scene( new Group( YourNode ) );
    YourNode.applyCss( );
    YourColumn.setPrefWidth( YourNode.getLayoutBounds( ).getWidth( ) );
    

    You can get simple text width by using the javafx.scene.text.Text node, but it doesn't have some nice properties, you could use as padding.

  • How to enable multiple selection in a TableView via dragging the mouse

    Hello

    I work multiple selection in my TableView but only via the combination SHIFT + click or by using the keyboard, but how can I enable selection of multiple rows in the table via a drag of the mouse? It doesn't seem to work out of the box.

    Thank you

    Robert

    Take a look at this thread:

    Re: How can I select multiple cells in tableview with javafx only with the mouse?

  • Problem with JavaFX 8 not clearing tableview

    Hello

    Got a number of JavaFX programs I convert between JavaFX 8.0 on a computer virtual Windows 8.1

    Programs strongly make view summary data and updates automatically or on demand via the selection of different parameters.

    The typical lines of code that do this work are (excerpts of a typical program):

    @FXML

    private TableView < QASL2TrendsData > eventTable = new TableView <>();

    .. .do stuff

    final ObservableList eventData < QASL2TrendsData > = FXCollections.observableArrayList ();

    eventData.removeAll (eventData);

    eventData.clear ();


    .. .do stuff through a task, including

    eventData.add (new QASL2TrendsData (year janEvents, febEvents, marEvents, aprEvents, mayEvents, junEvents, julEvents, augEvents, sepEvents, octEvents,))

    novEvents, decEvents, minEvents, maxEvents, meanEvents, medianEvents, stdDevEvents, predictEvents, slopeEvents, minMagnitude, maxMagnitude,

    meanMagnitude, medianMagnitude, stdDevMagnitude, predictMagnitude, slopeMagnitude));

    .. .do more things including what follows on the success of the task (in searchTask.setOnSucceeded)

    eventTable.setItems (eventData);

    Under JavaFX 2.2.60 the behavior of the code would result in the TableView is well updated with data updates to the ObservableList.  It would deal with the situation where the number of lines to display is greater than or equal to what could be displayed in the TableView (with scroll bar when it is required) and also when the number of lines to display was less than what could be displayed in the TableView.  In the latter case, a series of empty lines will appear below the actual data.

    What I found with the release of 8u5 JDK of JavaFX that this fact is more what is happening.  Where is the number of lines to display > = what can fit in the TableView all things are fine and they are displayed correctly.  The scroll bar adjusts accordingly and that data can be read depending on the features of JavaFX 2.2.60.

    BUT...

    Where the number of lines to display is less than what would fit in the TableView, previous row data of other updates remain and fills the TableView content for max height.  If I run the program and select settings to display a set of data that do not meet the TableView that everything is perfect.  But if a previous set of parameters had filled the TableView then when I run the program again the subset of data lines are displayed and then all previous data fill the rest of the size of the TableView.  It should have displayed blank lines below the actual data as in the case of JavaFX 2.2.60

    I googled my heart out and I tried several approaches, but in vain. Start writing the code to write blank lines in the TableView (up to the maximum number that could integrate) to force the remaining data to clear.  Then thought this is crazy the thing should work as before.

    Someone out there please have a solution / work around can I ask if I can complete my migration through 8u5 Java and the new JavaFX?

    I hope you can help!

    Thank you

    Peter

    Yes, a juggling cell custom factories.

    If I added "setText (null)" before «if (item!» (= null)"the remaining lines are suppressed.

    Weird how this behavior changed in javafx 8.

    Anyway thanks for your help, that the problem is now solved!

    Can move on the conversion of the rest of my programs

  • TableView Single Cell selection style

    Model selection TableView allows you to select individual cells in the table, but the default style highlights the entire line, regardless of the column that is selected on the line.

    I wonder what options are there to change this behavior so that the actual cell (row/column) highlighted instead of the whole line.

    Something like the cell $18,000 in the 'presentation of the Figure 1 Table' in https://wiki.openjdk.java.net/display/OpenJFX/TableView+User+Experience+Documentation

    Are you sure that you define the selection properly model?

        tableView.getSelectionModel () .setSelectionMode (SelectionMode.SINGLE);
        tableView.getSelectionModel () .setCellSelectionEnabled (true);

    A style like this should work:

    .table-view > .virtual stream > .clipped-container > .the > .table-line-cell > cell .table: selected {}

    -fx-border-color: red;

    }

  • How to set a checkbox for an indefinite period in a TableView?

    I want to set a TableView with a column that contains a check box.

    This can be done with a statement like this: myColum.setCellFactory (CheckBoxTableCell.forTableColumn (myColumn);

    The problem is how to specify that the display check box is indeterminate?

    You will have to roll you own. The box is buried inside the CheckBoxTableCell. In addition, how you set the indeterminate state is based on the data, and the CheckBoxTableCell is based on a boolean, so only two States property.

    Here is an example that shows a check if the person is frequented your party a dash if they are not, a box unchecked if you just do not know:

        enum Attending { YES, NO, UNKNOWN }
    
        static class Person {
            final String lastName;
            final String firstName;
            ObjectProperty attending = new SimpleObjectProperty<>(Attending.UNKNOWN);
    
            public ObjectProperty attendingProperty() { return attending; }
    
            Person(String lastName, String firstName) {
                this.lastName = lastName;
                this.firstName = firstName;
            }
        }
    

    So for the table, do you something like this:

            Table table = new Table<>();
    
            table.setItems(FXCollections.observableArrayList(new Person("Data", "Test")));
    
            TableColumn attendingColumn = new TableColumn();
            attendingColumn.setCellValueFactory(param -> param.getValue().attendingProperty());
            attendingColumn.setCellFactory(param -> new TableCell() {
                final CheckBox checkBox = new CheckBox() { {
                    setAllowIndeterminate(true);
                }};
    
                @Override public void updateItem(Attending item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setGraphic(null);
                    } else {
                        switch (item) {
                            case YES:
                                checkBox.setSelected(true);
                                break;
                            case NO:
                                checkBox.setIndeterminate(true);
                                break;
                            case UNKNOWN:
                                checkBox.setSelected(false);
                                break;
                        }
                        setGraphic(checkBox);
                    }
                }
            });
            table.getColumns().addAll(attendingColumn);
    
  • Round corner in TableView header

    Hi, I do a bit of style in TableView. The result is nice but I can't do the round top left corner.

    This is the actual result:

    http://snag.Gy/kkf7v.jpg

    .table-view {
        -fx-background-color: transparent;    
    }
    
    /*HEADER */
    .table-view .column-header{       
        -fx-background-color: #27A5F9;    
        -fx-size: 45.0px;
        -fx-min-height: 45.0px;    
        -fx-cursor: hand;
    }
    
    
    .table-view .column-header .label {
        -fx-font-size: 1.083333em;
        -fx-font-weight: bold;    
        -fx-text-fill: white;
        -fx-alignment: center-left; 
        -fx-padding: 5.0 5.0 5.0 5.0;
    }
    
    
    .table-view .filler{
        -fx-background-radius: 0.0 5.0 0.0 0.0;  
        -fx-background-color: #27A5F9;    
        -fx-size: 45.0px;
        -fx-min-height: 45.0px;    
    }
    
    .table-view .show-hide-columns-button{
        -fx-background-color: #27A5F9;    
    }
    
    .table-view .column-drag-header{
        -fx-background-color: #27A5F9;
        -fx-cursor: h-resize;
    }
    
    .table-view .column-resize-line{
        -fx-text-fill: white;
        -fx-background-color: white;
        -fx-fill: white;
        -fx-border-color: white;
        -fx-border-width: 1;
    }
    
    .table-view .column-header .sort-order{
        -fx-text-fill: white;
        -fx-fill: white;
    }
    
    
    .table-view .placeholder{
         -fx-background-color: white;    
    }
    
    .table-view .placeholder .label {
        -fx-font-size: 1.1em;
        -fx-font-weight: bold;    
        -fx-text-fill: #27A5F9;
        -fx-alignment: center; 
    }
    
    
    .table-view .virtualflow{
        -fx-background-color: white;
    }
    
    /* Each row in the table is a table-row-cell. Inside a table-row-cell is any
       number of table-cell. */
    .table-row-cell {
        -fx-background-color: transparent;   
        -fx-border-width: 0.0;
        -fx-padding: 10.0 0.0 10.0 0.0;    
        -fx-pref-height: 45.0px;  
    }
    
    
    .table-row-cell:filled:even{
        -fx-background-color: white;
    }
    
    
    .table-row-cell:filled:odd{
        -fx-background-color: #F6F7F8;
    }
    
    
    .table-view:row-selection .table-row-cell:filled:hover {
        /*-fx-background-color: red;*/
    }
    .table-view:row-selection .table-row-cell:filled:hover .text{
        /*-fx-fill: white;*/       
    }
    
    
    .table-row-cell:filled:focused {
        -fx-background-color: #e1e2e3;           
        -fx-background-insets: 0.0;
    }
    
    
    .table-row-cell:filled:focused .text{    
    }
    
    
    .table-row-cell .table-column{
        -fx-border-width: 0.0;    
        -fx-padding: 0.0 0.0 0.0 5.0;     
    }
    
    /*TESTO DELLE CELLE */
    .table-row-cell .text{
        -fx-font-size: 1.1em;
        -fx-fill: #6F7B8A;
    }
    
    /*SCROLL BAR VERTICALE */
    .table-view .scroll-bar:vertical{        
        -fx-padding: 0.0 0.0 0.0 0.0;
    }
    
    /*SCROLL BAR ORIZZONTALE */
    .table-view .scroll-bar:horizontal {
        -fx-padding: 0.0 0.0 0.0 0.0;
    }
    

    I would also like to le at the top left corner has been round.



    Thank you

    Hey there, I did header .column and .filler transparent and added your value of Blue ray and corners to the .column-in-head-background who worked for me

    .table-view {
        -fx-background-color: transparent;
    }
    /*HEADER */
    .table-view .column-header{
        -fx-background-color: transparent;    /* made transparent */
        -fx-size: 45.0px;
        -fx-min-height: 45.0px;
        -fx-cursor: hand;
    }
    .table-view .column-header .label {
        -fx-font-size: 1.083333em;
        -fx-font-weight: bold;
        -fx-text-fill: white;
        -fx-alignment: center-left;
        -fx-padding: 5.0 5.0 5.0 5.0;
    }
    .table-view .filler{
        -fx-background-radius: 0.0 5.0 0.0 0.0;
        -fx-background-color: transparent;    /* made transparent */
        -fx-size: 45.0px;
        -fx-min-height: 45.0px;
    }
    .table-view .show-hide-columns-button{
        -fx-background-color: #27A5F9;
    }
    .table-view .column-drag-header{
        -fx-background-color: #27A5F9;
        -fx-cursor: h-resize;
    }
    .table-view .column-resize-line{
        -fx-text-fill: white;
        -fx-background-color: white;
        -fx-fill: white;
        -fx-border-color: white;
        -fx-border-width: 1;
    }
    .table-view .column-header .sort-order{
        -fx-text-fill: white;
        -fx-fill: white;
    }
    .table-view .placeholder{
         -fx-background-color: white;
    }
    .table-view .placeholder .label {
        -fx-font-size: 1.1em;
        -fx-font-weight: bold;
        -fx-text-fill: #27A5F9;
        -fx-alignment: center;
    }
    .table-view .virtualflow{
        -fx-background-color: white;
    }
    /* Each row in the table is a table-row-cell. Inside a table-row-cell is any
       number of table-cell. */
    .table-row-cell {
        -fx-background-color: transparent;
        -fx-border-width: 0.0;
        -fx-padding: 10.0 0.0 10.0 0.0;
        -fx-pref-height: 45.0px;
    }
    .table-row-cell:filled:even{
        -fx-background-color: white;
    }
    .table-row-cell:filled:odd{
        -fx-background-color: #F6F7F8;
    }
    .table-view:row-selection .table-row-cell:filled:hover {
        /*-fx-background-color: red;*/
    }
    .table-view:row-selection .table-row-cell:filled:hover .text{
        /*-fx-fill: white;*/
    }
    .table-row-cell:filled:focused {
        -fx-background-color: #e1e2e3;
        -fx-background-insets: 0.0;
    }
    .table-row-cell:filled:focused .text{
    }
    .table-row-cell .table-column{
        -fx-border-width: 0.0;
        -fx-padding: 0.0 0.0 0.0 5.0;
    }
    /*TESTO DELLE CELLE */
    .table-row-cell .text{
        -fx-font-size: 1.1em;
        -fx-fill: #6F7B8A;
    }
    /*SCROLL BAR VERTICALE */
    .table-view .scroll-bar:vertical{
        -fx-padding: 0.0 0.0 0.0 0.0;
    }
    /*SCROLL BAR ORIZZONTALE */
    .table-view .scroll-bar:horizontal {
        -fx-padding: 0.0 0.0 0.0 0.0;
    }
    /* I ADDED THIS */
    .table-view .column-header-background {
      -fx-background-radius: 5.0 5.0 0.0 0.0;
        -fx-background-color: #27A5F9;
    }
    

Maybe you are looking for