JTable CellRenderer and NULL cells

Hi,
I have a table where several cells have "nulls" in them. I want to set the backgound color of my cells. I use:
  myTable.setsetDefaultRenderer(Object.class, new MyCellRenderer());where MyCellRenderer extendsDefaultTableCellRenderer
This works fine for all cells except when a cell has a null value in it. Than the renderer is never called. Is there a solution?
Here is the code for MyCellRenderer:
class MyCellRenderer extends DefaultTableCellRenderer {
  public Component getTableCellRendererComponent
          (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    // Obtains default cell settings
    Component cell = super.getTableCellRendererComponent ( table, value,isSelected, hasFocus, row, column);
    if (row % 2 == 0)
      cell.setBackground(Color.blue);
    else
       cell.setBackground(Color.gray);
    if (column % 2 == 0) cell.setBackground(Color.green);
    return cell;
}Thanks
SUP

Register your renderer with the TableColumn or register the class related to your renderer with the TableColumn.
Basically, JTable retrieves its editors and renderer from a hashtable, and nulls cause a problem.
Consider some type of intelligent data wrapper that contains a null data value, but it itself is not null. Or maybe a null token class.
-jonathan

Similar Messages

  • JTable - help with custom cell renderers and editors

    I've got myself into a bit of a mess with cell renderers and editors.
    I've got a custom component that wants displaying in a column and then hand over all functionality to this component when you start editing it.
    Now how I went out about this was to create a custom cell renderer that extends this component and implements TableCellRenderer.
    I then created a table cell editor that extends AbstractCellEditor and implements TableCellEditor and this cell editor creates a new component when it's initialized. I then use setCellEditor(new MyCellEditor()) on the column and setCellRenderer(new MyCellRenderer()).
    This works slightly but I'm wondering how this is all implemented.
    When I set the cell editor on it's own it seems to be sharing a reference to the single component that's being used which means that if you edit one cell all the cells get changed to the new value.
    Thanks for the help,
    Alex

    only a few forums are actually browsedAnd theSwing forum is one of the most active. Did you search it for editiing examples? I've seen many editing examples posted in a SSCCE format.
    SSCEE is also impossible as the functionality spans over about 10 classes We did not ask for your application, we asked for a SSCCE. The whole point of a SSCCE is to simplify the 10 classes into a single class and maybe an inner class for the editor to make sure you haven't made a silly mistake that is hidden because of the complexity of your real application.

  • How do I create a JTable with some empty cells in it?

    I have a three column JTable. The first column is a String showing description. The second column contains numbers (double) and the third column also contains numbers. In some cases not all cells in a row should contain data. So for instance, I could have row one showing only description (a String in the first column), and then row two showing description (a String in the first column) and a number (a double in the second column) in columns one and two respectively. My problem is that, the data gets copied from the cells with data to the cells which are supposed to be empty. So, how do I create a JTable with some empty cells in it.

    I have tried empty strings for those values, but it did not work. My table puts objects in an arraylist called reconciliation. The arraylist takes different objects with the same super class. The code below explains. Are you suggesting I pass null to my constructor?
    JTable table = new JTable(new ReconTableModel());The method below is from the table model
    protected  List<Reconciliation> reconciliation = new ArrayList<Reconciliation>();
    protected void fillModel(){
          reconciliation.add(new CashBook("Cash Book Report"," "," "));
          reconciliation.add(new CheckingBankAccount("Checking Bank Account"," "," "));
          reconciliation.add(new BankBalance("Bank Balance As Per Bank Statement",500," "));
          reconciliation.add(new PaymentVouchers("Payment Voucher Receipt",300," "));
          reconciliation.add(new DepositVoucher("Deposit Voucher Receipt",1000," "));
          reconciliation.add(new ReconciledBalance("Reconcilied Bank Balance",1200," "));
          reconciliation.add(new BalanceAt("Bank Balance At",800," "));
          reconciliation.add(new Difference("Difference",400," "));
          Collections.sort( reconciliation, new Comparator<Reconciliation>(){
          public int compare( Reconciliation a, Reconciliation b) {
            return a.getTransactionName().compareTo( b.getTransactionName());
      }

  • Jsf data table component + print null cell

    I am using the jsf data table component and binding the column values to a backing bean.
    <h:dataTable binding="#{backing_showDifferences.dataTable2}"
    id="dataTable2">
    <h:column binding="#{backing_showDifferences.userColumn1}"/>
    <h:column binding="#{backing_showDifferences.userColumn2}"/>
    <h:column binding="#{backing_showDifferences.userColumn3}"/>
    </h:dataTable>
    - some code from my showDifferences.java
    HtmlOutputText column1Text = new HtmlOutputText();
    vb =
    FacesContext.getCurrentInstance().getApplication().createValueBinding("#{users.uclass}");
    column1Text.setValueBinding("value", vb);
    usercolumn1.getChildren().add(column1Text);
    HtmlOutputText column2Text = new HtmlOutputText();
    vb =
    FacesContext.getCurrentInstance().getApplication().createValueBinding("#{users.ue1}");
    column2Text.setValueBinding("value", vb);
    usercolumn2.getChildren().add(column2Text);
    HtmlOutputText column3Text = new HtmlOutputText();
    vb =
    FacesContext.getCurrentInstance().getApplication().createValueBinding("#{users.ue2}");
    column3Text.setValueBinding("value", vb);
    usercolumn3.getChildren().add(column3Text);
    ResultSetDataModel dataModel = new ResultSetDataModel();
    dataModel.setWrappedData(rs);
    dataTable2.setValue(dataModel);
    The raw HTML:
    <table id="form1:dataTable2" class="iuptable" border="1">
    <thead>
    <tr>
    <th scope="col">Heading 1</th>
    <th scope="col">Heading 2</th>
    <th scope="col">Heading3</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>some data in this column</td>
    <td>X</td>
    <td></td>
    </tr>
    <tr>
    <td>Some more data in this row</td>
    <td>X</td>
    <td></td>
    </tr>
    </tbody>
    </table>
    My problem is this...in the raw HTML the <td></td> tag is not formatted nicely on my table output. I have lines around my entire table and each cell within it. When the <td></td> prints there are no lines. I am new to the JSF table data component, but if I were writing some JSP or servlet code I would check that if value was null I would append an &nbsp to the <td> tag (ex. <td>&nbsp</td>) and the table would be formatted properly. The backing bean that I am binding to is pulling the data from a database table...so my sql looks like this:
    SELECT uclass, ue1, ue2 from table1; my problem is when ue1 or ue2 is a null value.
    Any ideas would be greatly appreciated!

    Hi,
    the h:dataTable belongs to the JSF Reference Implementation from Sun, not to Oracle ADF Faces. The rendering is within this component set and I suggest to report your issue on one of the SUN forums (http://forum.java.sun.com/forum.jspa?forumID=427) as we have no handle to e.g. fix an issue if it exists in the component set.
    Frank

  • JTable how to set cell ediatble false

    - Can teach me JTable how to set cell ediatble false?
    - And I'm not so understand about following method and sentence...
    addRowSelectionInterval(int index0, int index1)
    Adds the rows from index0 to index1, inclusive, to the current selection.
    - Then what is toggle? What is the usage? How to use?
    - Then how to add one more row in the Jtable?

    - Can teach me JTable how to set cell ediatble false?check the method isCellEditable()
    Use DefaultTableModel
    - And I'm not so understand about following method and sentence...
    addRowSelectionInterval(int index0, int index1)
    Adds the rows from index0 to index1, inclusive, to the current selection.
    - Then what is toggle? What is the usage? How to use?
    - Then how to add one more row in the Jtable?[JTable API|http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTable.html]

  • [Forms10] + Client_Ole2 problems on getting null cell

    Hi,
    I've a little problem on excel file import to oracle form.
    When my excel cell have a value all works fine, but if i try to get a null cell value with "client_ole2.get_char_property" i get the WUO-714 error.
    I've used the same function in oracle form 4.5 and i've never got any problem.
    Thanks all

    Hi,
    I have same requirement to get data from Excel cell in form 10g. Can you help me by the way send to me your sample code.
    Many thanks for your help!
    BACH

  • Dates in Jtable - tried and tried and tried

    I have a table cell renderer to handle the date fields as follows.
    The dates appear MM/dd/yyyy when the table is loaded as I want.
    SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
    if (((Vector)fieldInfo.elementAt(i)).elementAt(2).equals ("DATE")) {
          // set format for date display
         column = PassportTable.getColumnModel().getColumn(i);
         // Now get column renderer
         // and set cell renderer for column
         column.setCellRenderer(new DefaultTableCellRenderer() {
              public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                   Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                    // Create and put formatted date in cell
                   setText(cdnDate.format((java.util.Date)value));
                   return renderer;
    );The problem I have is I cannot get the date that appears as the user edits the field
    in this format. I have got yyyy-MM-dd for example the cell shows "01/01/1900"
    when the user starts to edit the field "1900-01-01" appears. I have managed
    to make a variety of different formats appear but never the one I want.
    I have tried the many variations of the following two methods to edit a date in a table cell.
    Nothing I have tried has worked.
    public void setUpDateEditor(JTable table) {
         //Set up the editor for the date cells.
         try {
              String str = "01/01/1900";
              java.util.Date passDate = cdnDate.parse(str);
              final LimitedDateField dateField = new LimitedDateField(passDate);
              DefaultCellEditor dateEditor = new DefaultCellEditor(dateField) {
                   public Object getCellEditorValue() { // return a date
                        //return new java.util.Date(dateField.getValue()); //no compile
                        return dateField.getValue();
              table.setDefaultEditor(java.util.Date.class, dateEditor);
         catch (Exception showUpdatelEx) {}
    Where my LimitedDateField class is as follows:public class LimitedDateField extends JTextField implements GlobalInterface {
         private Toolkit toolkit;
         private SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
         private char slaSign = '/';
         private int columnLimit;
         private java.util.Date retVal;
         public LimitedDateField(java.util.Date value) {
              //super(columns);
              columnLimit = 11;
              toolkit = Toolkit.getDefaultToolkit();
              setDocument(new DateDocument());
              setValue(value);
         public java.util.Date getValue() {
              String str = "01/01/1900";
              try {
                   // retVal = cdnDate.parse(str);
                   retVal = cdnDate.parse(getText());
              catch (ParseException e) {Toolkit.getDefaultToolkit().beep();}
              return retVal;
         public void setValue(java.util.Date value) {
              setText(cdnDate.format(value));
         protected class DateDocument extends PlainDocument {
              public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
                   char[] source = str.toCharArray();               
                   char[] result = new char[source.length];
                   char[] hResult = new char[source.length]; // save
                   int j = 0;
                   if (super.getLength() > columnLimit - 1){toolkit.beep();}
                   else {
                        for (int i = 0; i < result.length; i++) {
                             if (Character.isDigit(source)) {result[j++] = source[i];}
                             else if (source[i] == slaSign) {result[j++] = source[i];}
                             else {toolkit.beep();}
    When this failed I tried something simpler - to no avail.
    public void setUpDateEditor(JTable table) {
         //Set up the editor for the date cells.
         try {
              SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
              DateFormatter df = new DateFormatter(cdnDate);
              JFormattedTextField ftf1 = new JFormattedTextField(df);
         catch (Exception showUpdatelEx) {}Any suggestions????
    Thanks
    rykk

    Try again as Format code missing
    I have a table cell renderer to handle the date fields as follows.
    The dates appear MM/dd/yyyy when the table is loaded as I want.
    SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
    if (((Vector)fieldInfo.elementAt(i)).elementAt(2).equals ("DATE")) {
          // set format for date display
         column = PassportTable.getColumnModel().getColumn(i);
         // Now get column renderer
         // and set cell renderer for column
         column.setCellRenderer(new DefaultTableCellRenderer() {
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                   Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                    // Create and put formatted date in cell
                   setText(cdnDate.format((java.util.Date)value));
                   return renderer;
    );The problem I have is I cannot get the date that appears as the user edits the field
    in this format. I have got yyyy-MM-dd for example the cell shows "01/01/1900"
    when the user starts to edit the field "1900-01-01" appears. I have managed
    to make a variety of different formats appear but never the one I want.
    I have tried the many variations of the following two methods to edit a date in a table cell.
    Nothing I have tried has worked.
    public void setUpDateEditor(JTable table) {
         //Set up the editor for the date cells.
         try {
              String str = "01/01/1900";
              java.util.Date passDate = cdnDate.parse(str);
              final LimitedDateField dateField = new LimitedDateField(passDate);
              DefaultCellEditor dateEditor = new DefaultCellEditor(dateField) {
                   public Object getCellEditorValue() { // return a date
                        //return new java.util.Date(dateField.getValue()); //no compile
                        return dateField.getValue();
              table.setDefaultEditor(java.util.Date.class, dateEditor);
         catch (Exception showUpdatelEx) {}
    }Where my LimitedDateField class is as follows:
    public class LimitedDateField extends JTextField implements GlobalInterface {
         private Toolkit toolkit;
         private SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
         private char slaSign = '/';
         private int columnLimit;
         private java.util.Date retVal;
         public LimitedDateField(java.util.Date value) {
              //super(columns);
              columnLimit = 11;
              toolkit = Toolkit.getDefaultToolkit();
              setDocument(new DateDocument());
              setValue(value);
         public java.util.Date getValue() {
              String str = "01/01/1900";
              try {
                   // retVal = cdnDate.parse(str);
                   retVal = cdnDate.parse(getText());
              catch (ParseException e) {Toolkit.getDefaultToolkit().beep();}
              return retVal;
         public void setValue(java.util.Date value) {
              setText(cdnDate.format(value));
         protected class DateDocument extends PlainDocument {
              public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
                   char[] source = str.toCharArray();               
                   char[] result = new char[source.length];
                   char[] hResult = new char[source.length]; // save
                   int j = 0;
                   if (super.getLength() > columnLimit - 1){toolkit.beep();}
                   else {
                        for (int i = 0; i < result.length; i++) {
                             if (Character.isDigit(source)) {result[j++] = source[i];}
                             else if (source[i] == slaSign) {result[j++] = source[i];}
                             else {toolkit.beep();}
    When this failed I tried something simpler - to no avail.
    public void setUpDateEditor(JTable table) {
         //Set up the editor for the date cells.
         try {
              SimpleDateFormat cdnDate = new SimpleDateFormat("MM/dd/yyyy");
              DateFormatter df = new DateFormatter(cdnDate);
              JFormattedTextField ftf1 = new JFormattedTextField(df);
         catch (Exception showUpdatelEx) {}Any suggestions????
    Thanks
    rykk

  • How can a TableView iterate over Rows and get Cells?

    I need to iterate over all the rows in a TableView without using Events. I would like to get the total number of rows, the TableRow, and a Cell from a specified TableColumn in the TableRow.
    Something like this:
    for(TableRow tableRow: tableView.getRows()){
        Cell cell = tableRow.getColumn(4).getCell();
        // do something to the cell
    }Is this possible?
    Edited by: Conzar on May 19, 2013 11:18 PM

    However, the problem with the CheckBox has been resolved so I don't need to iterate over the rows any longer.Yep, not using lookups to handle this is a much better solution, I just provided my lookup based solution because you asked for an iterative solution.
    The (lookup) code below doesn't produce any output.It works for me, I included an executable sample so you can try it out.
    My guess is that you aren't taking into account the fact that the lookup is just a snapshot of the table's cells at a moment in time.
    If you do a cell lookup before you show the table on a stage, it's not going to return anything because the cells are only generated on an as needed basis and there is no need to generate any cells before displaying the table on a stage.
    I get the following output on Java8b89 Win7:
    NumberedTableViewSample$2$1@344fe46[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@44187690[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@34618adc[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@61eb7609[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@50b006a1[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@307d4153[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@89b7483[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@70ce61fd[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@178969ad[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@e3149ea[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@3683d879[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@589e421f[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@7e26215b[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@69d59720[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1ad26ff1[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@32b058e4[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@582e254[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@261c4ebd[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@2cb9cfb[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@63c6fe00[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@16a98443[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@58247401[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@34dc3da4[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@78a62ea[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@29e0032e[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1781c971[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@18b2e479[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@4801295b[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@19e4c622[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@6a766d41[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@572aed5d[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@3bdf71a4[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@524c48c7[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@47b5a3ea[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@6ef8b38b[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@7fd2ee72[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@4994195c[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@49620450[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@246d8751[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@17e90472[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@def00[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@d1aa50a[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@2a7a58ba[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@2675cbd1[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@1c06ee08[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1685718d[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@6ba1936c[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@61ef15e5[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@6b2ace30[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@3c4d17c7[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1c3c9aad[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@27eadfe[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@3f83a064[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@579615f1[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@52a9271b[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1d221557[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@18947d9e[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@537eab32[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@687cc257[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@3d524978[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@44554375[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@22f89594[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@1f891aaf[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@bafcb2f[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@7ddeea8c[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@26023325[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@4b14700f[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@89eb58[styleClass=cell indexed-cell table-cell table-column]
    NumberedTableViewSample$2$1@6a55a4a6[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@7d95454d[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@375592eb[styleClass=cell indexed-cell table-cell table-column]
    TableColumn$1$1@7add3f35[styleClass=cell indexed-cell table-cell table-column]TestApp:
    import javafx.application.Application;
    import javafx.beans.property.ReadOnlyObjectWrapper;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.value.ObservableValue;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Node;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableColumn.CellDataFeatures;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class NumberedTableViewSample extends Application {
        private TableView<Person> table = new TableView<>();
        private final ObservableList<Person> data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(470);
            stage.setHeight(500);
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
            table.setEditable(true);
            TableColumn numberCol = new TableColumn("#");
            numberCol.setMinWidth(20);
            numberCol.setCellValueFactory(new Callback<CellDataFeatures<Person, Person>, ObservableValue<Person>>() {
              @Override public ObservableValue<Person> call(CellDataFeatures<Person, Person> p) {
                return new ReadOnlyObjectWrapper(p.getValue());
            numberCol.setCellFactory(new Callback<TableColumn<Person, Person>, TableCell<Person, Person>>() {
              @Override public TableCell<Person, Person> call(TableColumn<Person, Person> param) {
                return new TableCell<Person, Person>() {
                    @Override protected void updateItem(Person item, boolean empty) {
                        super.updateItem(item, empty);
                        if (this.getTableRow() != null && item != null) {
                          setText(this.getTableRow().getIndex()+"");
                        } else {
                          setText(null);
            numberCol.setSortable(false);
            TableColumn firstNameCol = new TableColumn("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName"));
            TableColumn lastNameCol = new TableColumn("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName"));
            TableColumn emailCol = new TableColumn("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("email"));
            table.setItems(data);
            table.getColumns().addAll(numberCol, firstNameCol, lastNameCol, emailCol);
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
            // this lookup set won't print anything as no cells have been generated.
            for (Node r: table.lookupAll(".table-row-cell")){
                for (Node c: r.lookupAll(".table-cell")){
                    System.out.println(c);
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
            stage.setScene(scene);
            stage.show();
            // now the table has been initially rendered and it's initial set of cells generated,
            // the cells can be looked up.
            for (Node r: table.lookupAll(".table-row-cell")){
                for (Node c: r.lookupAll(".table-cell")){
                    System.out.println(c);
        public static class Person {
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            public String getFirstName() {
                return firstName.get();
            public void setFirstName(String fName) {
                firstName.set(fName);
            public String getLastName() {
                return lastName.get();
            public void setLastName(String fName) {
                lastName.set(fName);
            public String getEmail() {
                return email.get();
            public void setEmail(String fName) {
                email.set(fName);
    }

  • How let Empty (NULL) cells in Matrix Report to show a 0 value

    I am working on a Matrix report in Oracle 9i environment. The report involves lots of grouping and calculations. Everything works fine, except for the Empty (NULL) cells. If a group did not get a concrete
    Returned value (NULL), the cell would be empty. The data layout is as following:
    District_Name
    Total      Failed      %Failed
    10 5 %50
    For some District, all 3 cells are empty, (with NULL values returned, I guess). As a result, all 3 cell for that District show nothing. End users required all cells with a meaningful value (e.g. 0). At same time they want all the value in a grid style (outlined). With null values, all 3 cell merged into one empty "big" cell".
    Any friends can help?
    I would like to express my appreciation here.
    AChen

    Without seeing your query, sounds like you either need:
    a) an outer join
    b) an NVL function
    If you are pulling data from multiple tables, and you are doing direct joins, and data from one table is not present in another, an outer join would get the other data.
    You should also use NVL if you need a 0. If a field is not populated, but you want to default it to zero, use the NVL function.
    If all else fails, you could make the fields formula fields. In the formula you could put this pseudocode:
    IF :cf_cell1 is null
    then return 0;
    else return :cf_cell1;
    end if;Just an idea - if none of those suffice, post your query and maybe we can help.
    Good luck!

  • Difference between Null and null?

    What is the difference between null and NULL?
    When is each used?
    Thanks,

    veryConfused wrote:
    There is a null in java, but no NULL. null means no value. However, when assigning value, the following is different:Although the empty String has no special role. Null means, the referential type is not assigned (doesn't refer) to a specific object. The empty String is just another object though, so seeing it or pointing it out as something special when it actually isn't at all (no more special than new Integer(0) or new Object[0]) just adds to the confusion.

  • How to differentiate the EMPTY Records and Null Values in DSO

    Hello....how is everyone here?? Ehehehe!
    I try to load some data from the flat file which contains some EMPTY data and Null Values for the records. The data type for the InfoObjects of the fields "Quantity" is "number". The sample data from the flat file (CSV) are as below:
    Food              Quantity
    Hamburger  -       12
    Cheese        -       0
    Vegetable      -               (Empty)
    When I try to load the above sample data to the DSO, I get the results of the data as follow:
    Food              Quantity
    Hamburger     - 12.000
    Cheese           -  0.000
    Vegetable         - 0.000
    In this case, how can the user differentiate whether the records is contain empty value of null values in DSO? This is kinda of hard to differentiate the both scenarios above. Is there any way to differentiate the scenarios described here?
    Thanks alot =)

    Hi Fluffy,
    It depends on the initial values of the data type
    The inital values For quantity/Currency/ Numbers it takes spaces as 0
    for char it is SPACE
    We cannot differeniate between space and null values.
    IF you have to force this then define quantity as char and load the data. we will not have units and aggregation in this case.
    Hope this helps.
    PV

  • How to force simple tags and null attributes to appear when using SQL/XML?

    Hello everybody:
    I'm developing a non-schema based XMLType view.
    When the XML document is generated, i noticed two things I need to manage in order to achieve the desired result:
    1. Oracle generates a <tag></tag> pair for each XMLELEMENT defined; in my case, some tags need to appear as <tag/>... how do I do? Is it possible when using schema based XMLType views? Is it possible while using a non-schema approach?
    2. When using XMLATTRIBUTE('' AS "attribute") or XMLATTRIBUTE(NULL AS "attribute"), no one attribute with label "attribute" and null value appears at the output; how do I force to Oracle DB to render those attributes which are with no values (needed to render those attributes as another parsing code will await for all the items)?
    3. Some tip about how to route the output to an XML text disk file will be appreciated.
    Thanks in advance.
    Edited by: Enyix on 26/02/2012 11:21 PM
    Edited by: Enyix on 26/02/2012 11:22 PM

    Hello odie_63, thanks for your reply:
    Reasons why needed single tags are these two next: Needed to generate a single XML file from 50,000,000 rows, where the XML ouput matches not only row data but another default values for another elements and attributes (not from database but using strings and types with default values); by using start and end tag, the generated file is as much twice bigger than using single tags; second, needed a very precise presentation for all the document.
    For generating that document, currently focus is based on using a batch process relying on Spring Batch with using a single JDBC query where a join happens between two tables. From my point of view, that approach uses: database resources, network resources, disk resources, and processing resources, including the price of making the join, sending to network, creating objects, validating, and making the file (Expending too much time generating that XML file). That processs currently is in development.
    I think possibly another approach is delegating the complete generation of that file to the database using its XML capabilities. My current approach following your recomendations is to generate a clob where I will put all the XML and putting it into a table. It leads me to another issues: Considering limitations on memory, processing and disk space, needed to append a single row-as-xml into the clob as soon as possible, and putting the clob inside the field as soon as possible, or putting the clob inside the field, and appending into it as the data is generated; so How do I manage the process in order to achieve that goals?. Seen these issues aren't related to my original question, so I'll open a new post. Any help will be apreciated.
    Thanks again in advance.

  • How to check empty string and null? Assign same value to multiple variables

    Hi,
    1.
    How do I check for empty string and null?
    in_value IN VARCHAR2
    2. Also how do I assign same value to multiple variables?
    var_one NUMBER := 0;
    var_two NUMBER := 0;
    var_one := var_two := 0; --- Gives an error
    Thanks

    MichaelS wrote:
    Not always: Beware of CHAR's:
    Bug 727361: ZERO-LENGTH STRING DOES NOT RETURN NULL WHEN USED WITH CHAR DATA TYPE IN PL/SQL:
    SQL> declare
      2    l_str1   char (10) := '';
      3    l_str2   char (10) := null;
      4  begin
      5  
      6    if l_str1 is null
      7    then
      8      dbms_output.put_line ('oh STR1 is null');
      9    elsif l_str1 is not null
    10    then
    11      dbms_output.put_line ('oh STR1 is NOT null');
    12    end if;
    13  
    14    if l_str2 is null
    15    then
    16      dbms_output.put_line ('oh STR2 is null');
    17    elsif l_str2 is not null
    18    then
    19      dbms_output.put_line ('oh STR2 is NOT null');
    20    end if;
    21  end;
    22  /
    oh STR1 is NOT null
    oh STR2 is null
    PL/SQL procedure successfully completed.
    SQL> alter session set events '10932 trace name context forever, level 16384';
    Session altered.
    SQL> declare
      2    l_str1   char (10) := '';
      3    l_str2   char (10) := null;
      4  begin
      5  
      6    if l_str1 is null
      7    then
      8      dbms_output.put_line ('oh STR1 is null');
      9    elsif l_str1 is not null
    10    then
    11      dbms_output.put_line ('oh STR1 is NOT null');
    12    end if;
    13  
    14    if l_str2 is null
    15    then
    16      dbms_output.put_line ('oh STR2 is null');
    17    elsif l_str2 is not null
    18    then
    19      dbms_output.put_line ('oh STR2 is NOT null');
    20    end if;
    21  end;
    22  /
    oh STR1 is null
    oh STR2 is null
    PL/SQL procedure successfully completed.
    SQL> SY.

  • Varchar2, empty strings and NULL

    Hi all,
    When inserting an empty string into a column of type varchar2 - is a NULL value stored in the column by the database? I've seen conflicting reports, and I know that the SQL 1992 spec specifies that empty strings not be treated as a NULL value, but that Oracle has traditionally treated zero length strings stored in a varchar2 column as NULL.
    So, is there a way to store an empty string in a varchar2 column as an empty string and not a NULL value?
    TIA,
    Seth

    It can be even more complicated or annoying than NULL not equal to ASCII NULL.
    example:
    create table test_null
    (fld1 varchar2(10),
    fld2 varchar2(10),
    fld3 varchar2(20));
    insert into test_null values (chr(0),null, 'chr(0) and null');
    insert into test_null values (null, null, 'null and null');
    insert into test_null values ('', chr(0), ''''' and chr(0)');
    insert into test_null values ('', null, ''''' and null');
    select * from test_null;
    FLD1       FLD2       FLD3
                          chr(0) and null
                          null and null
                          '' and chr(0)
                          '' and null
      1  DECLARE
      2  BEGIN
      3   for c1 in (select fld1, fld2, fld3 from test_null) loop
      4      if c1.fld1 = c1.fld2 then
      5         dbms_output.put_line(c1.fld3||' Are equal'||
      6                '  Length fld1 = '||to_char(length(c1.fld1))||
      7                ' Length fld2 = '||to_char(length(c1.fld2)));
      8      else
      9         dbms_output.put_line(c1.fld3||' Are NOT equal'||
    10                '  Length fld1 = '||to_char(length(c1.fld1))||
    11                ' Length fld2 = '||to_char(length(c1.fld2)));
    12      end if;
    13      dbms_output.put_line(' ');
    14   end loop;
    15*  END;
    SQL> /
    chr(0) and null Are NOT equal  Length fld1 = 1 Length fld2 =
    null and null Are NOT equal  Length fld1 =  Length fld2 =
    '' and chr(0) Are NOT equal  Length fld1 =  Length fld2 = 1
    '' and null Are NOT equal  Length fld1 =  Length fld2 =
    PL/SQL procedure successfully completed.

  • Difference between IS NULL and = NULL

    Hello Guys,
    In 10gR2 what is the difference between IS NULL and = NULL
    Thanks,
    Imran

    Just don't use the second, because the comparison operator = cannot deal with NULLs as you (probably) hope it can:
    SQL> create table t1 as select rownum as id, 'test' as word from dual connect by level<=2;
    Table created.
    SQL> update t1 set word=null where id=1;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL> select * from t1;
            ID WORD
             1
             2 test
    SQL> select * from t1 where word is null;
            ID WORD
             1
    SQL> select * from t1 where word = null;
    no rows selectedKind regards
    Uwe Hesse
    http://uhesse.wordpress.com

Maybe you are looking for

  • Mail keeps crashing when opened

    I had some trouble with my mac yesterday and had to delete everything and do a recovery, now wverything works except from the mail, it crashes everytime I open it.. Is there anything I can do to fix it? Here's the problem report: Process:         Mai

  • ICal Color Coding for Family Members on on Master Calendar?

    I have a very detailed ical calendar for all the family members' activities & would like to view them with a different color per person on one single calendar. I am not clear whether creating a calendar per person in a group will allow me to then mer

  • How can I make an Apple ID as a developer for apps ?

    How can I create an app and then post it to the App Store ???

  • Error while creating routing in CA01

    Hi, I'm trying to create a routing for a material using CA01 in dev environment. I have given the input of a material number and plant that exists in the system, but when i execute it throws an error saying "Material type ZPRD is not defined for task

  • Adobe Bridge Missing

    Hello all, I have Master Collection and up till recently had Adobe Bridge installed. I say up till recently because It's been on my machine for a while now, then a few days ago I installed Premier Pro to my system and now bridge is MIA. I can see in