TreeView with icons displayed incorrectly after expansion (8 JavaFX)

I have a TreeView with classes CellFactory and TreeCell custom, which has been implemented in JavaFX 2.2 and works perfectly. However, after I upgraded to 8 JavaFX. This tree is completely messed up. If I develop a nodes, there will be duplicate tree nodes in the tree. Here is a simplified version of the source code. If not use a method setGraphic() in class TreeCell, it works fine.

package test;


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.util.Callback;


public class TreeViewTest extends Application {
    private static final Image image = new Image(TreeViewTest.class.getResourceAsStream("icon_datasource.png"));
    
    public TreeViewTest() {
    }


    @Override
    public void start(Stage primaryStage) {
        BorderPane rootPane = new BorderPane();


        TreeItem<String> root = new TreeItem<String>("Root");
        
        for (int i = 0; i < 5; i++) {
            TreeItem<String> ds = new TreeItem<String>("Datasource " + i);
            
            for (int t = 0; t < 5; t++) {
        TreeItem<String> tb = new TreeItem<String>("Table " + t);
        ds.getChildren().add(tb);
            }
            
            root.getChildren().add(ds);
        }
        
        TreeView<String> tree = new TreeView<String>();
        tree.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
     
     public TreeCell<String> call(TreeView<String> param) {
  return new TreeCell<String>() {
     @Override
     protected void updateItem(String item, boolean empty) {
         super.updateItem(item, empty);
         
         if (!empty) {
             ImageView imageView = new ImageView(image);
             setText(item);
             setGraphic(imageView);
         }
     }
  };
     }
  });
        tree.setRoot(root);
        tree.setShowRoot(false);
        
        rootPane.setLeft(tree);
        
        Scene scene = new Scene(rootPane, 1024, 800);


        primaryStage.setTitle("Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

In general, cells are reused as items in TreeView (and some make, and ListViews) as soon as they become visible and invisible. It is perfectly possible for a cell to have an element that is not empty and then it change to empty, as the cell is reused for an empty cell.

If you have a bug in your code: you need

tree.setCellFactory(new Callback, TreeCell>() {

            public TreeCell call(TreeView param) {
                return new TreeCell() {
                    @Override
                    protected void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);

                        if (!empty) {
                            ImageView imageView = new ImageView(image);
                            setText(item);
                            setGraphic(imageView);
                        } else {
                            setText(null);
                            setGraphic(null);
                        }
                    }
                };
            }
        });

You lucky in JavaFX2.2 that the re-use of cell does not seem to affect your bug. improving the effectiveness of the re-use of the cell in JavaFX 8 has exposed the problem.

Furthermore, it is generally a bit pointless to re - create the nodes each time than updateItem (...) is called (frequently), rather than create them once when the cell is created (much less often). So consider

tree.setCellFactory(new Callback, TreeCell>() {

            public TreeCell call(TreeView param) {
                return new TreeCell() {
                    private ImageView imageView = new ImageView(image);
                    @Override
                    protected void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);

                        if (!empty) {
                            setText(item);
                            setGraphic(imageView);
                        } else {
                            setText(null);
                            setGraphic(null);
                        }
                    }
                };
            }
        });

Instead

Tags: Java

Similar Questions

  • Websites displaying incorrectly after reset - Strange bars horizontal across the screen.

    Hi all

    Recently, AVG has updated on my PC. I'm normally on the ball with this stuff and always avoid the add ons auto install tools for search free etc, but this one slipped in front of me. The end result is that whenever I opened a new tab AVG had diverted FF and I was presented with an AVG search page. Trying to get rid of him without success so reset FF.

    Since that some sites (not all) have display problems. Most affected appear to be Ebay and FB. What happens is after the page loads and I scroll through the major part of the page of disappears behind black and grey horizontal bars. It was certainly not like it before delivery to zero so something wrong obviously walk in the settings but I could do with help on which parameters must be twisted re. If this can help I can take a screenshot of the problem and host it.

    In case its relevant I am running Win 7 ultimate 64-bit.

    Thank you very much, Chris

    Because the reset Erases a lot of settings, changes may have done and forgotten a long time ago can be once again. Here are a few thoughts:

    (1) try to disable the use of Firefox hardware acceleration

    When Firefox is not entirely compatible with the driver for your graphics card, there may be seeds of inexplicable display. The standard solution is to fall back to the most basic rendered graphic to see if this can help, especially if the issue cannot be resolved by updating your graphics drivers.

    You can disable hardware acceleration here:

    "3-bar" menu button (or tools) > Options > advanced

    In the mini ' General' tab, uncheck the box for "use hardware acceleration when available.

    That will take effect the next time you exit and restart Firefox.

    (2) disable or remove unnecessary extensions

    Open the page modules using either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Then, for acts recognized or non-essential, turn off.

    Typically, a link will appear above at least an extension disabled to restart Firefox. You can complete your work on the tab and click one of the links in the last step.

    (3) disable unnecessary plugins

    Open the page modules using either:

    • CTRL + SHIFT + a
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click on Plugins. For non essential or mystery plugins, change the selector to "activate" to "never activate. Depending on the nature of the plugin, this can help as soon as you reload the tab, or it could take effect only in a new window launched after the change.

    Even if #1 or #2 fix the visible problems, I suggest to complete these three steps.

    Any improvement?

  • Help! Records is 'My Computer' are more grouped separately, like a normal folder view with icons appearing one after another

    I have Windows XP Pro SP3, after I shut down my computer one day and handed back upward, the look has changed to 'MY COMPUTER', they were prominent groups such as "Shared folders", "Hard drive" and "devices with removable storage".  Now, the Group disappeared and all that remains is the drives and folders in a page layout, like how a regular all types one after the other.  How to get back the old look with them separate?

    Click view > rearrange icons by > Type and view > rearrange icons by > show in groups .

  • Icons displayed incorrectly at startup, the computer is unusable for several minutes

    My computer is less than a year, I'm running Windows 7 Professional, and for several weeks my computer acted strangely. When I turn on the screen displays properly, however some or all (it seems to change every time) of my icons appear as these things white paper folded. It continues for several minutes during which I can't run any programs, but I can use my mouse pointer and the loading symbol when I move the taskbar. After a 5-10 minutes (I've not timed, but it might be compatible), the icons to revert to the normal and my computer seems to work perfectly well. Any idea what the problem might be?

    When a Windows computer starts in place, some of the non-Windows installed on the computer programs also starts alongwith. In your case, it seems that some of these startup programs is responsible for the delay. You can disable startup programs and services non-Windows on the computer by placing the computer in what is called a "Clean-boot". If the problem does not appear in the clean boot state, you can track Windows service start defective or not programme following a policy of division and conquere.

    This process takes a little time. I would say by following the instructions in the following article to diagnose the problem:

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

  • Web pages displayed incorrectly after the upgrade to Firefox 10.0.2

    Many web pages is not correctly displayed after upgrading to Firefox 10.0.2. Also, I'm not able to view YouTube videos. I checked my plug-ins and all are up-to-date, including Adobe Flash Player 11.1.102.62. I have no problem when you use Chrome on the same computer. Also, my laptop on the same network running Firefox 3.6.14 and works well. TIA, carlier

    Hello

    Please also try this: (Alt + T) Tools > clear recent history, choose all in the interval of time to clear the cookies and the Cache in the Details. Recent history of claire

  • UNREAD message icon display incorrect account blackBerry smartphones!

    At the top of my screen, the unread message icon still more messages than exist. Currently, it is said that I have 1 unread SMS message. When I receive an SMS, it will go up to 2. This will be the case and it will say 20 BBM or 3 emails but I still have to find a solution.

    Tips to clear the message unread... try them in the order.

    If you have a new icon rogue Message on your home screen, or a negative number (-1), one of these solutions could erase or reset:

    Try these options:
    * Hard Reset BlackBerry now ALT CAP (right Shift key) and DEL (or with the BlackBerry power, remove the battery and reinsert the battery)
    Messages > saved Messages
    Messages > view folders, check each folder (calls, SMS and MMS, and boxes, saved missed boxes, browser, phone logs etc.)
    * Scroll at the top of the folder, on the title menu, click or tap to MARK PRIOR OPEN date
    Change your theme and see if it persists and return to your desired theme. (Options > theme > select.)
    * Clean and reload your OS.
    ESET and restart your BlackBerry.

  • Why PDF with transparency displayed incorrectly?

    Hello world

    I used this script ( http://www.adobe.com/devnet/digitalpublishingsuite/articles/dps-pdf-to-indesign.html ) to create a magazine based on a PDF file, but I have a big problem.

    PDF imported with transparent elements are not properly displayed, but only in a vertical position as you can see in the pictures on the menu and horizontal display correctly.
    I don't have control of PDF files because the Publisher send it already ready.

    I used the v.22 for this publication because I can't update the application now, but I installed the latest tools DPS.

    Thanks in advance for the help.

    http://www.cityrailways.it/storage/esempi/Esempio1.jpg

    http://www.cityrailways.it/storage/esempi/Esempio2.jpg

    I know this is an old thread, but I want to answer because it'll be useful for someone looking for answers as if I was today ;-)

    This is an expected behavior for a PDF article. Articles only PDF supports transparency opacity effect and multiply, blend modes are not supported. However, the content even if it is downloaded as a PNG/JPEG article should work correctly.

    It is also documented in best practices presented here Digital Publishing Suite help | Best practices to create overlays for

  • website displaying incorrectly after download

    I downloaded my site I did Muse to my external host. In safari, it loads perfectly however in chrome and internet explorer, it loads funny. I even added the Center to the widget page and tried to get all the items on pages to extend to 100% of the width always no chance.

    Any help would be greatly appreciated.

    www.zionfredericksburg.org

    Hello tiffanyt416245,

    Thank you for sending me the file.

    Here are my observations for 2 issues you mentioned

    1. white rectangle under the menu isn't full width

    Then rectangle square on the page master "main Zion" going to the outside page area.

    This won't work in all screen sizes, to ensure that it remains full width in all sizes screen you use the button of width of 100%.

    To do that select the rectangle and press 100% with button in the toolbar as shown in the screenshot.

    2 slide show is not full width.

    Slide show is placed in the "Home" page and has the similar problem. You have increased the width of the target, but it will not make full screen in most screens.

    You cannot use 100% option you use a Widget for Composition. I have 2 suggestions for you.

    Suggestion 1:

    If you want to create a 100% with the slide show then try slideshow widget instead of composition as a slide show widget, you get the possibility to apply 100% width on the Images of heroes. You can insert a slidwshows of the object > Inset Widget > slide show

    slideshow of width 100%. Adobe Muse CC tutorials

    Suggestion 2:

    If you want to use the composition on then you can try to create an illusion by placing a rectangle of width 100% on the back of the composition. But the background color used in the images must be the same as the color of the rectangle 100% width in the rear.

    Concerning

    Vivek

  • Fonts displayed incorrectly in Cyrillic

    Hello

    I have trouble with fonts display incorrectly in the browser preview. The problem is with only Cyrillic fonts.

    That's what I see in Design view.

    Screen Shot 2015-11-05 at 18.28.53.png

    And that's what it turns in a browser:

    Screen Shot 2015-11-05 at 18.29.09.png

    As you can see, the Cyrillic version is not displayed correctly.

    The problem is the same for all web fonts.

    What can be done to fix this? In addition, it is important for me not to use the format of the image, which is not a good workaround solution.

    Thank you

    Dmitry

    I found a solution by chance. Characters in the Web Page properties must be set to all. Problem solved.

  • iCal in doc icon displays an incorrect date

    iCal in doc icon displays an incorrect date.  with the help of el Capitan 10.11.5

    Open Terminal (in the Utilities folder) and type the following command (followed by Enter):

    Killall-KILL Dock

    If the problem returns, report.

  • display the icon mouse incorrect Photoshop 5.0

    After a recent Windows 7 upgrade my copy of Photoshop 5.0 began to display incorrectly.

    When you work in Photoshop a number of different tools is selected, and then the icon of this tool replaces the mouse arrow. These replacement tool icons are now corrupted and displaying a smaller version matrix dot instead, or not at all.

    I've deleted and reinstalled Photoshop several times without success to improvement. I tried all the options compatibility without success. I even went back to a version of 2013 Photoshop restoration and corrupted icons still appear.

    I did a full scan, deleted all unnecessary software, backed up my Photoshop files and worked my way through all of the suggestions of the Photoshop forum community, always without success.

    My only option is to believe that somehow, the upgrade to Windows 7 is the cause of my problem.

    Please notify.

    David Robertson

    Hello

    If you suspect a Windows update to be the cause of the problem, then let us know the number of the update. Here's how you can find the number:

    See the Windows updates are installed

    I suggest that you do a system restore. This will allow you to take the computer to a date before the installation of the update of Windows. Check if the problem persists.

    What is system restore?

  • Display text with icons

    JDev Version: 11.1.16

    I would like to display text with icons, when the text wrapping it looks like below

    for example. blah blah blah blah blah blah blah blah blah blah blah blah blah

    blah blah blah blah blah blah blah blah blah blah blah blah blah

    blah blah blah blah blah blah blah blah blah blah

    I tried with ADF CommandImageLink and goImageLink but these display the first icon next text.

    I also tried outputText and image, but the creation of two columns.

    Thank you

    Kala

    I tried with ADF CommandImageLink and goImageLink but these display the first icon next text.


    The default value is the first, but the position of the icon can be defined as an accompaniment with iconPosition.


    Icon="/images/search.gif".

    actionListener = "#{some.el.expression}" iconPosition = "creeping" / > "

  • I tried EvevryThing! The "CREATED WITH ADOBE ELEMENTS 9 TRAIL VERSION FIRST" will not stop Displaying, even after I put in the serial number and Regerstered. Also the product does not show under my profile?

    I tried EvevryThing! The "CREATED WITH ADOBE ELEMENTS 9 TRAIL VERSION FIRST" will not stop Displaying, even after I put in the serial number and Regerstered. Also the product does not show under my profile?

    How can I fix it? Nothing in help or on the Site.

    Once you have registered the product, you should not see the banner of 'Trial' on NEW projects. This isn't the case, right? You only see on the project that you created before you register the product, right?

    That said, to remove the banner, go to the folder of directory on your hard drive where your project PREL files are stored and delete the folder called Adobe Premiere elements preview files.

  • How can I make the favorite file as a desktop shortcut. Before having my calculation fixed, I had a shortcut on the desktop that displays all my favorites with icons?

    My computer repaired now requires that I go on Google etc. which at the favorite toolbar appears and when I click it I get my favorites OK listedn. Before the repair, I got a desktop shortcut that, once clicked gave me all my favorite disolayed on an entire page with icons. I know that the entire page is that I got once. but I can't seem to get it as a shortcut on the desktop. Can anyone help?

    In my computer | Local disk C | Documents and Settings. User name | Favorites. Right click on the Favorites folder and send to | Desktop computer.

  • Microsoft Office 2003 in Microsoft vista Ultimate icon display problem.

    Hello

    I have a computer laptop sony vaio with Windows Vista Ultimate Microsoft. I have connected to the external portable hard drive in Windows XP system as a hard drive. I got the backu. After that, I connected the hard drive of my laptop. then after Microsoft Office icons are not showing in correctly. its unknown icon of projection. but my office applications work properly. Can I recharge the icons as a same as before. I use office 2003.

    Can someone help me please.

    I don't know if it will work in these conditions, but you can try to rebuild the icon cache:http://www.vistax64.com/tutorials/117229-icon-cache-rebuild.html.

    If it does not, go to Windows Explorer and check C:\Program Files\Microsoft\Office\ (at this point I don't know what he could tell - perhaps Office 11 or something like that - because I don't have any more than the desktop version and I forgot how the folder structure is named - but you want the folder containining (, all the program icons to start the Office programs) and see if the executable program icons have changed as well.  If not, right-click on each one and then click on create a shortcut (desktop) - do it twice, so you will have one for the office and another to replace the one that is not going to start (and how much more you need based on the number of shortcut icons that you have).  If the icons of the programs also display incorrectly.

    If it does not, then there is no specific functionality of Ofice 2003 (or later versions) to simply change the icons to their original forms.  Try the repair Office option in the:http://support.microsoft.com/kb/821593.  One of the options included (that can be verified) is to restore the desktop shortcuts and which can solve the problem.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

Maybe you are looking for

  • iPhone 7 call low volume

    The volume of calls on my iPhone 7 is very low. I have the volume all the way up. Any ideas how can I fix?

  • How to install scan finger printing in Windows 7 32-Bit

    Hello world HP Pavilion dv6-2170ee Note Book it came with pre-installed, I had Windows 7 (64-BIT). Now, I have installed Windows 7 32 bit with your help, But, now, I am faced with a new problem how do you install security Finger Scanner printing ,. K

  • Android 2.2 (froyo) to charm please!

    Android 2.2 (froyo) to charm please!

  • Scanner does not work on HP Officejet 6500 Wireless with MacBook Pro

    I have the all-in-one Officejet 6500 wireless and print fine but the scanner does not work even after the implementation of suggestions on the Web site.  I recently installed Mac OS x 10.6.8 but I had the same problem with the previous software.  Sca

  • Minimize the problem of the user interface

    Hello: When using the top right minimize button in Teststand CVI Full-Featured user interface, by clicking on the item in the taskbar does not work to restore the display of the interface. Instead, to do a right click on the taskbar and choose "unmin