Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:18:25+00:00 2026-06-12T13:18:25+00:00

I am trying to follow this JavaFX 2 guide: http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJAGAAEE I use Scala instead

  • 0

I am trying to follow this JavaFX 2 guide:

http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJAGAAEE

I use Scala instead of Java and it looks like this for me:

<TableView fx:id="test">
     <columns>
         <TableColumn prefWidth="75.0" text="Message" />
     </columns>
</TableView>

And code:

val c = test.getColumns.get(0) // Get the first column.
c.setCellValueFactory(new PropertyValueFactory[Foo, _]("message")) // Foo is my model with a single SimpleStringProperty called "message".

val observableFoos = FXCollections.observableList(foos)
test.setItems(observableFoos)

The problem I have is that the setCellValueFactory line causes:

error: class type required but
javafx.scene.control.cell.PropertyValueFactory[com.myapp.models.Foo,
_] found c.setCellValueFactory(new PropertyValueFactoryFoo, _)

I don’t understand how I am supposed to use this method. If I replace _ with String, then I get:

error: type mismatch; found :
javafx.scene.control.cell.PropertyValueFactory[com.myapp.models.Foo,String]
required:
javafx.util.Callback[javafx.scene.control.TableColumn.CellDataFeatures[com.myapp.models.Foo,?0],javafx.beans.value.ObservableValue[?0]]
where type ?0 c.setCellValueFactory(new PropertyValueFactoryFoo,
String)

I can confirm that everything works fine if I remove the setCellValueFactory line — I just don’t see any content in the table — just blank rows as expected..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:18:26+00:00Added an answer on June 12, 2026 at 1:18 pm

    TL;DR: It is easy in java to silently bypass type safety with respect to type parameters.
    Scala won’t let you do that, short of performing an explicit cast.
    In addition, using Table.getColumns to retrieve the column means that the we lose the type of cell.
    Solutions: cast your TableColumn instance to the proper type, or instantiate the column by hand.

    The first problem lies in the signature of Table.getColumns: it returns a ObservableList[TableColumn[S,_]] (see http://docs.oracle.com/javafx/2/api/javafx/scene/control/TableView.html#getColumns()).
    So your c val is typed as TableColumn[Foo,_].
    This means that you lose the type of the cell content (denoted by the second type parameter).

    The only solution here is to properly type the column (c) using a cast:

    val c = test.getColumns.get(0).asInstanceOf[TableColumn[Foo, String]]
    c.setCellValueFactory(new PropertyValueFactory[Foo, String]("message"))
    

    This is quite logical: you have a list of columns where each column can contain objects of a different type. We would face the same dilemma with a scala List containing objects of different types, all unknown a priori: only a cast (or a match on the type, which is a cast in disguise) will let you get back the a specific type at compile time.

    Note also that in many JavaFx examples around the web, people don’t retrieve the columns through Table.getColumns. Instead, they instantiate them by hand and then call setCellValueFactory on it right after.
    Doing the same would solve your problem (without any need for a cast), as you will yourself specify the type parameters:

    val c = new TableColumn[Foo, String] // See ma, no cast!
    c.setCellValueFactory(new PropertyValueFactory[Foo, String]("message"))
    

    Now, you might look at some java examples and notice that they don’t actually provide any type parameter when instantiating their TableColumn:

    TableColumn c  = new TableColumn();    
    c.setCellValueFactory( new PropertyValueFactory<Foo,String>("name"));
    

    And indeed it does compile. How so? Well the sad truth is that the above code is not safer than doing a cast, as it relies on java’s backward compatibility for pre-generics aware classes.
    In other words, because c is typed as just TableColumn and not TableColumn<?, String> by example, the java compiler treat it as a non generic class and not perform any type checking regarding the type parameters of TableColumn.
    Contrast this to what happens if you explictly set the type of c to a generic type (but with an unknwon cell type):

    TableColumn<Foo, ?> name  = new TableColumn("Name");
    name.setCellValueFactory( new PropertyValueFactory<Room,String>("name"));
    

    In this case the compiler emits a type mismatch error:

    error: method setCellValueFactory in class TableColumn<S,T> cannot be applied to given types;
    ...
    

    This is just like in scala when c is typed as TableColumn[Foo, _]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to follow this documentation on Symfony : http://symfony.com/doc/current/book/forms.html ok so here is
I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
I'm trying to follow Sun's JDBC tutorial at http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html It gives the following example
I've been trying to follow this Railscast: http://railscasts.com/episodes/213-calendars I've implemented the controls and all
I am using Rails 3.0.7 and I am trying to follow this Railscast: http://railscasts.com/episodes/182-cropping-images
Im trying to follow this guide: http://www.castleproject.org/others/nvelocity/usingit.html Can you tell me what dlls I
I'm trying to follow this tutorial - http://www.dotnetcurry.com/ShowArticle.aspx?ID=231&AspxAutoDetectCookieSupport=1 I have both the vsdoc file
I'm trying to follow this beginner tutorial about Google Charts: http://code.google.com/p/gwt-google-apis/wiki/VisualizationGettingStarted I already have
I'm trying to follow this tutorial for an Accordion control in WPF: http://www.c-sharpcorner.com/UploadFile/dpatra/538/ I
I'm trying to follow this tutorial using StructureMap : http://iridescence.no/post/Constructor-Injection-for-ASPNET-MVC-Action-Filters.aspx What I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.