0

enter image description hereI want set the the graphics of starting cell to an eror image when there is any error in the table view data(any row data).I am using the following code inside the update method.

public void updateItem(String item, boolean empty) {

          super.updateItem(item, empty);
          String text = getString();
          setText(empty ? null : text);
          String text2 = text.trim();

          boolean isHex = text2.matches("^[0-9A-Fa-fx]+$");
          // Pattern compile = Pattern.compile("^[0-9A-Fa-fx]+.*");
          // Matcher matcher = compile.matcher(text);
          // boolean find = matcher.find();
          // getTableView().getColumns().;
          setGraphic(null);
          if (!isHex) {
            getStyleClass().add("oneCell");

            // this.setTextFill(Color.RED);
            // getTableView().getColumns().get(0;
            revertbackchanges();
            Image error = new Image(getClass().getResourceAsStream("twobuttons/icon_error_1.png"));

          } else {
            setGraphic(null);
            getStyleClass().remove("oneCell");
          }

here i am checking the cell data whether the data are hex value or not if other than hex is entered then i am changing the color of the cell to red .Now i want to show a error like icon on the 1st cell .How can i get the 1st cell from table view and set the graphics on it.As shown on image i can show an error with respective to cell on which user has entered the wrong value but along with that i want to show and error icon on Command cell i.e TX_default or i want to highlight the whole cell .Any help on this is really appreciated

Rajesh Kumar Dash
  • 2,203
  • 6
  • 28
  • 57

1 Answers1

1

this time its workied i tired..

Image img  =new Image(getClass().getResourceAsStream("Add-Male-User-icon.png"));
    ImageView imgs  =new ImageView(img);
tablecol.setCellFactory(new Callback<TableColumn<CheckDo, String>, TableCell<CheckDo, String>>() {

    @Override
    public TableCell<CheckDo, String> call(TableColumn<CheckDo, String> p) {


         return new TableCell<CheckDo, String>() {

        @Override
        public void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
            if (!isEmpty())
               this.setGraphic(imgs);
            }
        }
    };

enter image description here

Anshul Parashar
  • 3,096
  • 4
  • 30
  • 56
  • i could able to do that but along with it i want to set the graphics of 1st table view cell .Like some error icon – Rajesh Kumar Dash Nov 12 '13 at 11:54
  • @Rajesh use the same way but only change is that give you first column name like "userid" and the fire listner...after fire it break it at last means use it only once – Anshul Parashar Nov 12 '13 at 12:15
  • @Rajesh now i am edit above answer and its perfectly worked...i hope now you get – Anshul Parashar Nov 12 '13 at 12:23
  • ImageView is necessary for set image...image() just provide set image resource – Anshul Parashar Nov 12 '13 at 12:26
  • thanks for your support . I Could able to put color and graphics on the cell on which user is editing. But my requirement is to put a color or some error graphics on the table 1st cell . I have edited my query with an image please have a look at it. – Rajesh Kumar Dash Nov 13 '13 at 04:43
  • @Rajesh runtime it is not possible you can set particular cell property...you have to set muiltiple object observation lise.you have to set this at observationlist() time...where you set your table.. try this http://stackoverflow.com/questions/17067481/javafx-2-tableview-different-cell-factory-depending-on-the-data-inside-the-cel ...here you can get the solutions...if you like my answer vote it up :) – Anshul Parashar Nov 13 '13 at 05:20
  • @thanks anshul now i am thinking give the error icon on same cell and using setgraphics i can do that but can i replicate the same thing using the css.Any pointer on this will help me – Rajesh Kumar Dash Nov 13 '13 at 05:47
  • @Rajesh css for table is too much big...i cant not give it here...you ask new question "style of table" and give me here the link of question and there i give you default css of table :) – Anshul Parashar Nov 13 '13 at 06:02