Dynamic adding of components (doesn't work when programmatically)

Hi, I don't understand, why this doesn't work. I'll explain it on this example:
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class NewFXMain extends Application {
    Group root;
    public static void main(String[] args) {
        Application.launch(NewFXMain.class, args);
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World");
        root = new Group();
        Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
        Button btn = new Button();
        btn.setLayoutX(100);
        btn.setLayoutY(80);
        btn.setText("Add button now");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                addButton();
        root.getChildren().add(btn);  
        primaryStage.setScene(scene);
        primaryStage.setVisible(true);
        System.err.println("Number of buttons before: "+root.getChildren().size());
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
        executor.schedule(new MyTask(), 5, TimeUnit.SECONDS);
    private void addButton() {
        System.err.println("Button adding");
        root.getChildren().add(new Button("YEAH"));
        System.err.println("Number of buttons after: "+root.getChildren().size());
    class MyTask implements Runnable {
        public void run() {
            addButton();
}There are two ways how a new button can be added. Either by clicking on existing button or programmatically by the program itself after 5 seconds.
If you add it by button, there is no problem. The error print is:
Number of buttons before: 1
Button adding
Number of buttons after: 2
But if you just wait, then the error print is:
Number of buttons before: 1
Button adding
and no button is added. In fact, the error printing after the adding isn't performed either.
I'd like to ask if there is some solution for this because I'd love to do some changes by schedulers. Thx
Edited by: 876949 on 14.8.2011 9:09
Edited by: 876949 on 14.8.2011 9:11

No, these are not error messages, they are just for purpose of example. Here it doesn't matter whether err or out... (yes, 'out' would be better ;)
But thanx, it's working. By the way, I am creating scheduler for task lists. They are supposed to be printed dynamically in specific time (or periodically). For example: at 5 o'clock I need to print 5 items of some list and every 3 hours I need to print 3 items of another list etc. - so it's quite dynamic with regard to component adding (No, I don't want to use some sort of ListView, I want interactive printing: one item on screen at a moment). I'll try to work your solution into my code.
Edit: So either it's not possible to use this for the purpose of my app or it will be really cumbersome. Maybe it would be easier to draw some rectangles with mouse listeners...
Edit: So I finally got around it. In the end, I won't use dynamic adding as intended. It's working and that's important.
Edited by: 876949 on 14.8.2011 12:48
Edited by: 876949 on 15.8.2011 5:21

Similar Messages

  • [Photoshop CC 2014] Click&hold-move-release doesn't work when adding adjustment layer from the layer panel

    When selecting a menu item I used to click the left mouse button and hold it down, move the pointer to the desired menu item and release the mouse button. Everything works fine in the mine menu, but there's a problem when adding new adjustment layer from the layer panel: when I release the button nothing happens, I have to press the button again. In previous PS version it worked fine. How can I fix this?

    I don't think that is user fixable, meaning you'll have to wait till adobe fixes it with an update.
    Photoshop cc 2014
    windows does not work
    mac does work
    Did you already post over here:
    [Photoshop CC 2014] Click&hold-move-release doesn't work when adding adjustment layer from the layer panel

  • CS 4 Dynamic Link to Encore doesn't work most of the time.  Encore stops operating after opening and periodically Premier Pro stops working.  I'm told that there has been a problem with CS4 when using Dynamic Link to go to Encore and build CD's.  Is there

    CS 4 Dynamic Link to Encore doesn't work most of the time.  Encore stops operating after opening and periodically Premier Pro stops working.  I'm told that there has been a problem with CS4 when using Dynamic Link to go to Encore and build CD's.  Is there a way around this?  Is there a patch to correct it?

    To build CD's???
    What problem does Encore have with DL?
    If DL is not working properly for you the way around this is to export from Premiere to either mpeg2-dvd for DVD or BluRay H.264 for BD-disks and import the files in Encore.

  • My speaker doesn't work when I try to listen to music or open up a quick time file, however they seem to work perfectly when I listen to a voice memo (p.s. the volume slider disappears in a song page and even in the multi tasking bar)

    my speaker doesn't work when I try to listen to music or open up a quick time file, however they seem to work perfectly when I listen to a voice memo (p.s. the volume slider disappears in a song page and even in the multi tasking bar)

    Thanks for your solution, it wasn't quite what solved the problem but i remembered that i had a bit of salt water on my phone recently and spraying the charging port with an anti-oxide spray solved my problem, do you mind if i ask, how is the charging port related with the volume or/and speakers?

  • BitmapData draw method doesn't work when the project is published as the .swf file of the web applic

    Hi,
            I am totally confused by this strange error. When I tried using the draw method of BitmapData to draw a movieclip symbol of my project, it seems to work fine locally. However, as I uploaded the published .swf file to my web server and launched it as the plugin of my web application, it failed. The source codes as follows,
    function printscreenClicked():void
         //ExternalInterface.call calls a javascript function to print message1
        var bd:BitmapData = new BitmapData(stage.width,stage.height);
        //ExternalInterface.call calls a javascript function to print message2
      bd.draw(stage);
        //ExternalInterface.call calls a javascript function to print message3
    message3 didn't show at all. Instead, the browser console shows "Uncaught Error: Error calling method on NPObject.". My understanding of this error message is that the .swf is calling something crashing, and I believe that bd.draw(stage)is the crashng method call.
    Also, here is my html embed tag:
        <embed src="/tests/videoplayer.swf" id="flash" quality="high" height="510" width="990" scale="exactfit" name="squambido" align="middle" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" style="margin: 0px auto;clear:both;position:relative;"/>
    Can someone help me?

    Thank you for your reply.
    I tried stageWidth and stageHeight, but it still doesn't work.
    The draw() methid is triggered when I clicked a screenshot button in my application as follows,
    ExternalInterface.addCallback("printscreenClicked", printscreenClicked);
    function printscreenClicked():void
         //ExternalInterface.call calls a javascript function to print message1
        var bd:BitmapData = new BitmapData(stage.width,stage.height);
        //ExternalInterface.call calls a javascript function to print message2
      bd.draw(stage);
        //ExternalInterface.call calls a javascript function to print message3
    Would you please give me an example of "waiting for Event.RESIZE is good, or just at least Event.ENTER_FRAME"?
    My real purpose in this application is to capture a snapshot of a streaming video. The video is contained in a movieclip object. I tried stage first since BirmapData.draw() doesn't work when drawing the movieclip on the web site. Do you have any suggestion for this situation? Also, is there any good method to find out what happened if the browser have "Uncaught Error: Error calling method on NPObject."?

  • I have different account ID's with my iphone and computer. I would like to standardise both to just the one. One of the ID's doesn't work, when I tried to list the second email with the preferred one a message telling me that this email is already in

    I have different account ID's with my iphone and computer.
    I would like to standardize both to just the one.
    One of the ID's doesn't work, when I tried to list this second email with the preferred one a message telling me that this email is already in use pops up.. yes it is, with me??
    Is there an easy to fix this please, Fabfitz

    If the email address you want to use is being used as the primary email address on a different ID you have to manage that ID and change it to a different primary email address.  This explains how: Change your Apple ID - Apple Support.
    If it is being used as an alternate or rescue address on a different ID, you manage the ID and either remove it or change it to a different email address.  This explains how: Manage your Apple ID primary, rescue, alternate, and notification email addresses - Apple Support.

  • I have Adobe Acrobat 9.5.4 installed on my computer and it doesn't work when PDFing

    I have Adobe Acrobat 9.5.4 installed on my computer and it doesn't work when PDFing my document using Microft Word 2010. I have tried using the tab add-in, but it doesn't respond either. The only way to convert my document is to save it as a .pdf from the save as drop down box. I need to be able to have the full functionability of creating a PDF document with the tabs and links working.
    Please help!

    From OFFICE 2010 you either have to have AA X or just print to the Adobe PDF printer. You give no information on your operating system or specifically what you mean by PDFing -- there are multiple ways to create a PDF from a WORD document and you have given no information. However, in this case your only choice is to print to the Adobe PDF printer. Otherwise, you need to upgrade Acrobat.

  • TS1398 The internet on my Iphone 4 doesn't work when I use the Wifi

    The internet on my Iphone 4 doesn't work when I use the Wifi at home. My Mac works fine. On the Iphone it shows it's connected but it doesn't open any app. Anyone knows what to do? Thanks

    Ÿ. If you tap and hold the "Y" does it appear? If so, just slide your finger up to select.

  • It doesn't work when I press "transfer purchased items from ipod" and I don't know specidicly whitch item I need to transfer

    It doesn't work when I press "transfer purchased items from ipod" and I don't know specidicly whitch item I need to transfer.
    Whenever i press "transfer purchased items from ipod", itunes sync's for about 3 seconds, but I still can't install updates on the ipod without itues warning me about purchased items on the ipod, that aren't in the itunes library. I've tried folowing the steps in itunes help, but I can only find a step guide for when you know the specific item that needs transferring, and I donøt know that specific item.

    This Apple Tech Note explains the process:
    http://support.apple.com/kb/ht1848
    It will transfer all purchased items that the computer you are transferring to is authorised to play: you don't have to select the items.

  • I have recently upgraded to iPhone 5 from 4, call line identity doesn't work when call other iPhones.  It works when calling any other brand of cell phone.  Network carrier assures me problem is not on there side.  Any assistance will be appreciated.

    I have recently upgraded to iPhone 5 from 4, call line identity doesn't work when call other iPhones.  It works when calling any other brand of cell phone.  Network carrier assures me problem is not on there side.  Any assistance will be appreciated.

    I have recently upgraded to iPhone 5 from 4, call line identity doesn't work when call other iPhones.  It works when calling any other brand of cell phone.  Network carrier assures me problem is not on there side.  Any assistance will be appreciated.

  • Imessage doesn't work when i connect to my wifi only works on mobile date how do i fix this?

    Imessage doesn't work when i connect to my wifi only works on mobile date how do i fix this?

    1. Did you use Bootcamp Assistant?
    2. Did you build a USB with Windows 7 ISO and Bootcamp drivers?
    3. You should use a USB2.0 disk, not a USB3.0 disk (flash drive).
    4. What year is the Retina MBP?

  • My iPad takes hours to charge even when I turn it off I have bought like 6 chargers and my iPads been sent back twice and it still doesn't work when I'm charging it

    My iPad takes hours to charge even when I turn it off I have bought like 6 chargers and my iPads been sent back twice and it still doesn't work when I'm charging it what do I do ??

    I am also having the same problem.. Its too much annoying and its unfortunate nobody at apple support has anyclue of what is happening?
    ... This is happening almost most of the time keeping my phone down most of the times.

  • How do I delete items in my calendar when it doesn't work when I hover them over the trash can?

    How do I delete items in my calendar when it doesn't work when I hover them over the trash can?

    There are several ways
         - Selecting the event and hitting the "delete" key on your keyboard (as Wayne Contello said)
         - Selecting the event and opening the "edit" dropdown menubar item, and then selecting "delete"
         - Selecting the event and right clicking, then selecting "cut" (this option puts the event on your clipboard)

  • Collapse action doesn't work when several hierarchical columns in a report

    Hello everyone!
    I have an analysis which contains 6 hierarchical columns. And the problem is that for the 5th and 6th columns collapse doesn't work. I can easily expand the column, but I can't collapse it back. The first four columns are collapsing fine. Is there a bug which describes this?
    I'm using OBIEE 11.1.1.6.7. Tried to check this issue in Mozilla and IE - collapse didn't work in neither of them.

    It doesn't work here either. After checking the italicized bit below, I see that it doesn't work when called by an application either. It looks like a bug.
    Here's the fix I found here. Put it in the automator action "run Applescript"
    http://bbs.applescript.net/viewtopic.php?id=15292
    on run {input, parameters}
    --Pop Box
    display dialog "Automator hosed me with a bug, so I'm making you wait for 5 secs with delicious Applescript." giving up after 5
    return input
    end run
    The non-working solution :P
    One suggestion - split the workflow into two (or more) parts.
    1. Open Finder Items with Default Application
    2. Ask for Confirmation
    3. Run Workflow
    4. Wait for User Action
    5. Open Finder Items with Specific Application
    Save the first as an app, the second as a workflow.
    BG3, G4QS, G4ALPB   Mac OS X (10.4.3)  

  • OpenSuse Undo/Redo doesn't work when click on web links

    OpenSuse 12.2 Firefox 17 Undo/Redo doesn’t work when click on link . All web pages have some problem. Undo/Redo working for web page "Find" text box. All web pages

    Clear Cookies & Cache
    * https://support.mozilla.com/en-US/kb/Template:clearCookiesCache
    Clear the Network Cache
    * https://support.mozilla.com/en-US/kb/How%20to%20clear%20the%20cache#w_clear-the-cache
    Troubleshooting extensions and themes
    * https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes
    Check and tell if its working.

Maybe you are looking for

  • Safari quits unexepctedly when opening a specific page showing airline departures.

    So far this is the only page I have experienced that Safari quits and since I use this site frequently I appreciate very much advice on how to fix this The error message I recieve is as follows: Process:         Safari [4337] Path:            /Applic

  • Can I Turn a Video 90º?

    I shot a video holding my iTouch 4th gen vertically. When I e-mailed it, it appears 90º (sideways). The video is fairly important, so I'd like to know if there's any way to rotate it back such that it views normally when e-mailed. Photos are easy to

  • Lost all info I had on my calendar How do I get it back?

    Lost all info I had on my calendar.  Doctor apps etc.  One day it was there next day GONE!  How do I get them back?

  • IOS5 podcast tracks in an episode

    I am subscribed to several podcasts that DJs put in tracks from different artists, and i used to be able to see the name of the track and its artist in each segments in each episode of the podcast, After upgrading my iPad to iOS5, I can only see the

  • Landscape printing issue

    Is there a way to default Acrobat x to default to printing landscape?  I know we can choose this in the properties of the printer. My users would like to be able to skip this step