Cell TableView coloring on updates - realizing if sort happened

I'm doing has highlighted cells (in color) in a TableView whenever they are updated. My solution is based on the implementation of cell factories and use Animation (mounting) control cell background opacity - it works very well: whenever a cell value is updated, the background changes color, then fades away well.

The problem is, that if the table is sorted by clicking a column header, the underlying list is changed (of course), and the GUI level, it is also understood as a change and depending on the circumstances by cell (I flash a cell if its new value is different from the previous), several cells show an update unnecessarily (flashing).

I wonder how I could eliminate if a cell has been updated due to a 'real' update (an element has been updated) of the case when the list sort column and/or the order has been changed? I thought to catch the event of sorting (by adding an InvalidationListener to the sort order list) and ignore the updates, while it is underway, but I can't really know when it's over. I bet at the GUI level, there is no way to determine the reason, so I need a deeper understanding...

Thanks for the tips.

Register a listener for change with the appropriate property to change the highlight color for the cell according to the case. You need to do a bit of work to make sure that the listener is registered and non-registered as appropriate that the cell is reused for the different table elements: the trick is to use

Bindings.Select (tableRowProperty (), "point")

to get an observable of the current value of the line.

Update:

Well, the previous example did not work. For reasons I can't understand, after sorting (or scroll, in fact), the evil cell became the property change notifications.

So here's another strategy: keep track of the last known value of the cell line, and don't make the highlight is still called same rank value after the update. I prefer kind of the strategy described above, but I couldn't make it work.

import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.Duration;

public class TableChangeHighlightExample extends Application {

 @Override
  public void start(Stage primaryStage) {
    final Random rng = new Random();
  final TableView table = new TableView<>();
  table.getItems().addAll(createData(rng));

  TableColumn symbolColumn = new TableColumn<>("Symbol");
  TableColumn priceColumn = new TableColumn<>("Price");
  symbolColumn.setCellValueFactory(new PropertyValueFactory("symbol"));
  priceColumn.setCellValueFactory(new PropertyValueFactory("price"));
  priceColumn.setCellFactory(new Callback, TableCell>() {
      @Override
      public TableCell call(TableColumn table) {
        return new StockPriceCell();
      }
  });
  table.getColumns().addAll(Arrays.asList(symbolColumn, priceColumn));

  Timeline changeStockPricesRandomly = new Timeline(new KeyFrame(Duration.seconds(2), new EventHandler() {
    @Override
    public void handle(ActionEvent event) {
      StockValue stockToChange = table.getItems().get(rng.nextInt(table.getItems().size()));
      double changeFactor = 0.9 + rng.nextInt(200) / 1000.0 ;
      double oldPrice = stockToChange.getPrice();
      double newPrice = oldPrice * changeFactor ;
//     System.out.println("Changing price for "+stockToChange+" to "+newPrice);
      stockToChange.setPrice(newPrice) ;
    }
  }));
  changeStockPricesRandomly.setCycleCount(Timeline.INDEFINITE);
  changeStockPricesRandomly.play();

  BorderPane root = new BorderPane();
  root.setCenter(table);
  primaryStage.setScene(new Scene(root, 300, 400));
  primaryStage.show();
  }

  private List createData(Random rng) {
    return Arrays.asList(
      new StockValue("ORCL", 20.0 + rng.nextInt(2000)/100.0),
      new StockValue("AAPL", 300.0 + rng.nextInt(20000)/100.0),
      new StockValue("GOOG", 500.0 + rng.nextInt(100000)/100.0),
      new StockValue("YHOO", 20.0 + rng.nextInt(2000)/100.0),
      new StockValue("FB", 20.0 + rng.nextInt(1000)/100.0)
    );
  }

  public static void main(String[] args) {
  launch(args);
  }

  public static class StockPriceCell extends TableCell {
    private static final Color INCREASE_HIGHLIGHT_COLOR = Color.GREEN ;
    private static final Color DECREASE_HIGHLIGHT_COLOR = Color.RED ;
    private static final Duration HIGHLIGHT_TIME = Duration.millis(500);

    private static final NumberFormat formatter = NumberFormat.getCurrencyInstance();

    private final Label priceLabel ;
    private final Rectangle overlayRectangle ;
    private StockValue lastRowValue ;

    public StockPriceCell() {
      overlayRectangle = new Rectangle();
      overlayRectangle.setFill(Color.TRANSPARENT);
      overlayRectangle.widthProperty().bind(this.widthProperty().subtract(8));
      overlayRectangle.heightProperty().bind(this.heightProperty().subtract(8));
      overlayRectangle.setMouseTransparent(true);

      this.priceLabel = new Label();
      priceLabel.setMaxWidth(Double.POSITIVE_INFINITY);
      priceLabel.setAlignment(Pos.CENTER_RIGHT);
      StackPane pane = new StackPane();
      pane.getChildren().addAll(overlayRectangle, priceLabel);
      setGraphic(pane);
    }

    @Override
    protected void updateItem(Double price, boolean empty) {
      Double oldPrice = getItem();
      super.updateItem(price, empty);
      StockValue currentRowValue = null ;
      if (getTableRow()!=null) {
        currentRowValue = (StockValue) getTableRow().getItem();
      }
      if (empty) {
        priceLabel.setText(null);
      } else {
        priceLabel.setText(formatter.format(price));
        if (price != null && oldPrice != null && currentRowValue == lastRowValue) {
          if (price.doubleValue() > oldPrice.doubleValue()) {
            overlayRectangle.setFill(INCREASE_HIGHLIGHT_COLOR);
          } else if (price.doubleValue() < oldPrice.doubleValue()) {
            overlayRectangle.setFill(DECREASE_HIGHLIGHT_COLOR);
          }
          FadeTransition fade = new FadeTransition(HIGHLIGHT_TIME, overlayRectangle);
          fade.setFromValue(1);
          fade.setToValue(0);
          fade.play();
        }
      }
      lastRowValue = currentRowValue ;
    }
  }

 public static class StockValue {
    private final ReadOnlyStringWrapper symbol ;
    private final DoubleProperty price ;
    public StockValue(String symbol, double price) {
      this.symbol = new ReadOnlyStringWrapper(this, "symbol", symbol);
      this.price = new SimpleDoubleProperty(this, "price", price);
    }
    public final ReadOnlyStringProperty symbolProperty() {
      return symbol.getReadOnlyProperty();
    }
    public final String getSymbol() {
      return symbol.get();
    }
    public final DoubleProperty priceProperty() {
      return price ;
    }
    public final double getPrice() {
      return price.get();
    }
    public final void setPrice(double price) {
      this.price.set(price);
    }
    @Override
    public String toString() {
      return symbol.get() + " : " + price.get() ;
    }
  }
}

Post edited by: James_D

Tags: Java

Similar Questions

  • Every time I open Firefox I get the meesage from follopwing: it's recommended storngly you appl this update as soon as possible. When I have TRD to di, show he's trying to connect to the update server but nothing happens

    Everytime I open Firefox I get the following message: it is strongly recommended that you apply this update as soon as possible. When I try to do, is to show that it is trying to connect to the update server but nothing happens

    You are welcome

  • After that 'stop and install updates' on restart it happens to "configuration" 3/3 then restarts then does "configuration 3/3" again and restarts in a loop ""»

    This is windows vista business.

    After that 'stop and install updates' on restart it happens to "configuration" 3/3 then restarts then does "configuration 3/3" again and restarts in a loop. ""» I tried to find out latest fashion good and safe, but still the same. Help, please.
    Is it possible from a different drive to boot and then by applying some changes that would stop it. At the time when the computer is unusable, it just starts to "configuration updated 3/3" then restarts.

    Hello

    Try these methods.

    Method 1:

    You have to do a cold start, press and hold power for a few seconds (10).

    Wait a minute or two and turn it back on.

    Make sure that "all the" non-essential devices are disconnected. (USB keys (for example, flash drives) or any other external media like this takes place.).

    If you can, start safe mode.

    Start your computer in safe mode with network.

    http://Windows.Microsoft.com/en-us/Windows-Vista/start-your-computer-in-safe-mode

    NOTE: see 3 from the link above, Advanced options boot (including safe mode).

    http://Windows.Microsoft.com/en-us/Windows-Vista/advanced-startup-options-including-safe-mode

    Select Mode safe mode with networking.

    Method 2:

    Use the system restore feature:

    (a) click Start, type system restore in the Search box or search programs and filesand then click on the system restore under the programs section.

    (b) on the System Restore page, click Next.

    (c) select a restore point during which you know the operating system works, and then click Next.

    The restore point should be a date that precedes the first time you encountered the problem.

    NOTE: If you use system restore when the computer is in safe mode, you can't undo the restore operation.

    See also: error: configuration of the Windows updates failed. Restoration of the changes. Do not turn off your computer when you try to install updates for Windows

    http://support.Microsoft.com/kb/949358

    Data loss caveat:

    Be sure to back up data that you want to keep before you begin. This is to ensure that there is no loss of data.

    Method 3:

    Step 1:

    To avoid this problem on Windows Vista, obtain and install update 937287 from the Microsoft Download Center separately from all other updates on Windows Update site. Install the update that applies to your version of Windows Vista so that you are able to install future updates.

    A software update is available for the Windows Vista installation software feature

    http://support.Microsoft.com/kb/937287/en-us

    The following files are available for download from the Microsoft Download Center:

    Windows Vista x 86 systems

    http://www.Microsoft.com/download/en/details.aspx?amp;displaylang=en&ID=15287

    Windows Vista x 64 systems

    http://www.Microsoft.com/download/en/details.aspx?amp;displaylang=en&ID=23732

    Step 2:

    Save the update to a location on your hard drive, you can find and then install the update from there.

    Download, *Save* and install the update with no security (antivirus/security suite) software installed, disconnect from the Internet, disable the firewall & close all non-essential processes in the Task Manager.

    Disable antivirus programs and firewalls.

    Disable the anti-virus software

    http://Windows.Microsoft.com/en-us/Windows-Vista/disable-antivirus-software

    Windows Firewall

    http://Windows.Microsoft.com/en-us/Windows-Vista/firewall-frequently-asked-questions

    Note: Make sure that you enable the antivirus software, other security and firewall after the test programs.

    Caution:
    Antivirus software can help protect your computer against viruses and other security threats. In most cases, you should not disable your antivirus software. If you need to disable temporarily to install other software, you must reactivate as soon as you are finished. If you are connected to the Internet or a network, while your antivirus software is disabled, your computer is vulnerable to attacks.

    I also recommend taking off of USB keys (for example, flash drives) or any other external media, as this takes place.

    When the file is downloaded, see these steps.

    (a) right -click on the file and

    (b) select run as administrator from the menu.

    Check if it helps.

  • 2000 Basic and advanced license we run ISE 1.2, if we update 1.3, what happens to the license we must buy more / license apex

    2000 Basic and advanced license we run ISE 1.2, if we update 1.3, what happens to the license we must buy more / license apex

    When you migrate to 1.3, your license will be updated, advance licence, become apex

  • Staining of cells TableView (new)

    Here is another question from staining of cells with a different plug.

    You have a TableView with three columns - category, inside and out. You add a blank line and then you start to edit the category column. When you have added a category you want to see a change in the color of the other cells two columns in the same row as the value of the category.

    Say if the category is "income" then the cell 'In' will become green and the 'Out' cell becomes red. The important point here is that these cells and the underlying domain object has not all the values associated with these columns again. The cells are empty and color change is to show the user where the value must be set for the category concerned (in the green cell ).

    After that the category value is committed a 'message' must therefore being propagated in the category for the current line (or the entire table) column to extricate himself. I tried to call the following methods of method 'commit()' of the category column, but none of them does raise a repaint:

    -getTableRow () .requestLayout ();

    -getTableRow (.updateTableView) (getTableView ())

    -getTableRow (.updateIndex) (getTableView () .selectionModelProperty () .get () .selectedIndexProperty () .get ());

    Any suggestion of work would be more then welcomed.

    Once paint it is triggered then incoming and outgoing of cells in a table column can take the current value of the underlying domain object category (say MyRecord) like this

    Registration of MyRecord = getTableView () .getItems () .get (getTableRow () .getIndex ());

    String category = row.getCategory ();

    and call the setStyle ("...") on the cell to change the color.

    Isn't time for a complete example now, but a strategy is:

    Set a rowFactory on the table view that returns a table row that falls into the category for its corresponding article. Update the class style (in JavaFX 2.2) or a State of alright (in Java 8) for the row in the table according to the category.

    Define a factory of cells for columns that statically defines a class on cells (for example 'in' and 'out').

    Use an external style sheet that looks like this:

    .table-row-cell.income .table-cell.in, .table-row-cell.expenditure .table-cell.out {
    -fx-background-color: green ;
    }
    
    .table-row-cell.income .table-cell.out, .table-row-cell.expenditure .table-cell.in {
    -fx-background-color: red ;
    }
    

    Here is an example of a row of table factory that manipulates the class style of the table cell. There is a link to a version that uses Java 8 alright States, that is much cleaner.

  • javaFX 8: tableView color between the columns

    Hello

    In my TableView, columns are separated by gap (between white and light color).

    When I select a line, the color of these gaps is blue!

    Is it possible to set the color of these gaps?

    This is my CSS:

    .table-view: concentrate .table-line-cell: filled: selected {}

    -fx-background-color: #C0C0C0;

    -fx-background-inserts: 0.0, 0.0 0.0 0.0 0.0;

    -fx-text-fill:-fx-selection-bar-text;

    }

    Thanks in advance

    Kind regards

    Fabrice

    Thank you: it's perfect!

  • Camileo S30 - update firmware to sort power problems

    is there or will there ever a firmware update to sort the issues that a lot of people with me with power issues?

    Hello

    I checked the page of the European driver Toshiba Camileo updates, but no firmware update is available.
    If you have hardware problems, get in touch with a service provider in the country where you purchased the camera.
    The service provider is always your first point of contact and support you.

  • DeskJet F4140: Printer prints wrong colors after updating windows 10

    Hi all

    This is my first post here on the forums and it's a doozy.

    I've updated my laptop last night from 8.1 to win to win 10.  Power seems to work well except my Deskjet F4140 printer. It prints, but the colors are false.  bruises are red, red green, green are "purple", made for an interestng very a first impression. I did all the usual stuff, troubleshooting, test the page clean and align the heads. Uninstall and reinstall to make sure it was getting the windows 10 driver, but alas my problem remains. I tried to find a way to change the mode of compataibility and can't find my file .exe for the printer. I know it's and older printer, but it works like a top and I'd hate to have to replace it because of this problem.

    TLR

    update to win 10 and colors are off like hell.

    Thank you

    Robbie

    Finally fixed my printer not through HP. What I had to do is access the so-called Godmode on windows 10. It allows to access all the parameters of the user as well hidden and non-hidden in one place. I went down to my printer and changed its functioning as windows 8.1 and it works as it should. You should be able to learn more about the Google's God mode command line script. Thank you and good night.

  • Auto fill cells with color based on the result in the cell

    Is it possible to automatically fill a color in an excel cell based on the result that is displayed in a cell

    for example, if the result is in (0.00 - 1.00 = green), (superior to-2.00 orange)...

    -1.00
    0.54
    -2.50

    Hi CP.

    If you use excel 2007
    Use the conditional format in the home TAB
  • OfficeJet Pro 8100: Officejet Pro 8100 won't print color after update software on Mac

    I have a MacBook Air with OS X (Yosemite 10.10.3)-.

    When I connect the printer via USB, I was able to print by using the generic drivers on the machine. However, as expected, update software detected an update for HP drivers - I installed.

    And now the printer does not print in color. I checked every setting I can think, but it is still printing in black and white.

    Any help would be appreciated!

    Welcome to the @mandikayencforum!

    I have read your current position and the previous thread on how you were not and are not able to print in color from your Mac running 10.10. I saw that already test pages were color printing and would like to know if the test always pages print in color. If they do, a matter for the Mac somewhere, and I have some suggestions for you to do below. If the test pages no longer print in color, please let me know! If the printer is not printing in color when you print test pages, there is probably a problem of cartridge or printer hardware problem.

    1. follow the same steps of @Waterboy71 on your other thread here to reset the permissions system disk and repair of printing: Re: Officejet Pro 8100 refuses to print color (OS X 10.9)

    2. If you still do not have the ability to select the color printing on your Mac, try the procedure described in this post from wisgirl64: Re: won't print in color from my Mac or iPhoto for HP photosmart D110

    If you find that the color print test pages, and the Mac does not give you the options to choose color printing, I suggest getting in touch with Apple support experts to see if they can help fix the problem of the OS X.

    If you like my answer to you today, click the thumbs up below!

    Happy Friday!

  • Add Layer (overlay colors etc.) mess with sorting 3D effect.

    Bit of a weird one and I would say must be a bug.

    I have a complex walkthroughs 3D (branches, leaves, etc. of the tree) created from 2D Photoshop files.

    I wanted to add a bit of color in some of the layers using a color overlay.

    As soon as I apply the layer seems to go to the back of the composition ignoring its yard according to its position on the Z.

    The workaround I found is to re-arange the model as well as the layers are in the order they are in layers

    that is applying the style seems to be the layer back back to the 2D sort so put the layer I have first flythrough on the albums pop it back forward.

    However since my camera moves backwards in the Z of the comp plan that does not work in all cases.

    So for some, I had to comp before the offending layers and make color settings here.

    Not a huge mission, but not ideal for fine adjustment.

    I was wondering if anyone has a solution or just an explanation would be a good thing.

    See you soon

    Jono

    My system is brand new, so oven fresh installs of all.

    After Effects CS6 11.0.1.12

    Windows 7 Ultimate

    Intel Core i7 - 3770 K CPU @ 3.50 GHz

    32 GB of Ram

    NVIDIA GTX 690

    Solid State drive for system and cache.

    1 TB mirrored for project files.

    Bit of a weird one and I would say must be a bug.

    It is not a bug. It works as it should. Layer styles are applied after all the operations of the EA and thus break the 3D rendering. It's somewhere in the help. If you really need a few coloring Basic, to use other effects as fill, tint or whatever.

    Mylenium

  • Palette swatch InDesign CC from creating a new color or update a current color...

    InDesign CC crashed on me three times in a row and still won't solve his problem... EVEN AFTER my computer and all programs were closed during the night! I was in the shade palette to create a new shade. I had a course chosen to base a new one out of. I went to 'create new nuance,' the palette came, my mouse auto-défile when I clicked and it landed on "Color DIC." Now, the fields of the DIC does not disappear even when I'm in CMYK or RGB. And when I try to change it to CMYK or RGB color values, it blocks of InDesign. When I load up, the problem persists. How to reset it?

    See replace your preferences

  • How to eliminate the cell border color table

    The website that I'm getting is posted at http://www.100presentationstopremier.com/

    I am trying to remove the green lines bordering the horizontal orange stripe at the bottom of the header. I can't find any style of autocorrelation. I tried to change the color of brdr in the properties panel.

    Thank you

    It's in your CSS.

    #navigation a: hover {}
    background: #99CC66;
    color: #993300;
    }

    --
    Murray - ICQ 71997575
    Adobe Community Expert
    (If you * MUST * write me, don't don't LAUGH when you do!)
    ==================
    http://www.projectseven.com/go - DW FAQs, tutorials & resources
    http://www.dwfaq.com - DW FAQs, tutorials & resources
    ==================

    "David8765" wrote in message
    News:g4jjvm$NQF$1@forums. Macromedia.com...
    > The above does not appear in my source code page or opinion. Not 99CC66 or
    > the
    > stationary of terms or #navigation.
    >
    > But the buttons don't reversal and color is 99CC66.
    >
    > The site is displayed in http://www.100presentationstopremier.com
    >
    > Any suggestions? Thank you very much.
    >

  • Cell border color

    The first photo of the screen below is "not selected."  The second is "Most selected" and the third "selected."  The fourth has a very dark border, and many of my pictures in each folder this darker border.  That means the border more dark?

    Cell Borders.JPG

    It is part of a larger battery.

  • Clicking on a video clip selects the entire clip, rather than the range.  I did the update and it still happens.  Help!

    Problem * by clicking on a video clip selects the entire clip, instead of cuisiniere.* *.

    I restarted my computer like new.  Lost the iMovie app.  Re downloaded in the App Store.  Now I have a crappy iMovie on the App Store application.  Then I made, I got the updated version and I did.  Always update does not resolve the problem.  I'm sucking in a hole because I need to make new videos for work and I can't.  In addition, I'm too broke to buy Final Cut.  In addition, all apple stores have a waiting list of 5 days before they see you!  Thank you Apple with a 6 bites taken out of it!

    I had a similar problem and it was driving me crazy. I think you press and hold the 'R' key now to select a range, otherwise, it will select the whole clip. I think it's a goal a feature and not a bug? Hope that helps!

Maybe you are looking for

  • Satellite L500 - Webcam is grainy

    Yes as shown, I have recently purchased a Toshiba satellite L500 on a month and half ago.When I used the webcam it was fine, but then, all of a sudden it seems he has turned REALLY grainy, especially when, in low light conditions where it is used to

  • How to use Vista and Windows 98 on Satellite P100-150

    My P100-150 came with Vista.However I can't some of my old equipment as vinyl cutter use with it because it is not supported and the supplier of vinyl does not go to offer to all pilots.Someone can tell me how I put Windows 98 on the laptop and have

  • PXI-8431

    A question about the NI PXI-8431/8 serial port card: is it possible to directly control the TX (transmission) & read the RX (receive) state lines?    I need to implement a scheme of communication series using separate data and similar to SPI clock us

  • N020ca Pavilion: pavilion n020ca ram upgrade

    I want to install new ram but do not know what my computer needs. I have searched all over the site of HP but can't find ram info. Don't know I have a 2 GB and 4 GB installed but want to install at least one new stick 4 GB but want to buy the right t

  • Error Exaprom in deployed PDF error path and permission to application, how to solve this problem?

    Hello world