How to listen adding a new file to a folder to show up in JTable?










0















I have a problem with my GUI. I use WatchService and it works well. How can I add this service so that JTable will show a new file?



Maybe there is another solution? Can I ask you for some examples?
My table implements the AbstractTableModel.










share|improve this question



















  • 1





    Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

    – TT.
    Nov 15 '18 at 7:48











  • You use the addfRow(...) method of the DefaultTableModel to add the row.

    – camickr
    Nov 15 '18 at 15:22















0















I have a problem with my GUI. I use WatchService and it works well. How can I add this service so that JTable will show a new file?



Maybe there is another solution? Can I ask you for some examples?
My table implements the AbstractTableModel.










share|improve this question



















  • 1





    Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

    – TT.
    Nov 15 '18 at 7:48











  • You use the addfRow(...) method of the DefaultTableModel to add the row.

    – camickr
    Nov 15 '18 at 15:22













0












0








0








I have a problem with my GUI. I use WatchService and it works well. How can I add this service so that JTable will show a new file?



Maybe there is another solution? Can I ask you for some examples?
My table implements the AbstractTableModel.










share|improve this question
















I have a problem with my GUI. I use WatchService and it works well. How can I add this service so that JTable will show a new file?



Maybe there is another solution? Can I ask you for some examples?
My table implements the AbstractTableModel.







java swing jtable abstracttablemodel watchservice






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:33









Andrew Thompson

154k29165349




154k29165349










asked Nov 15 '18 at 7:17









PrzemekCPrzemekC

813




813







  • 1





    Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

    – TT.
    Nov 15 '18 at 7:48











  • You use the addfRow(...) method of the DefaultTableModel to add the row.

    – camickr
    Nov 15 '18 at 15:22












  • 1





    Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

    – TT.
    Nov 15 '18 at 7:48











  • You use the addfRow(...) method of the DefaultTableModel to add the row.

    – camickr
    Nov 15 '18 at 15:22







1




1





Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

– TT.
Nov 15 '18 at 7:48





Have the service listener add a row to the JTable. I'm sorry if it sounds so simple, but it is that simple really.

– TT.
Nov 15 '18 at 7:48













You use the addfRow(...) method of the DefaultTableModel to add the row.

– camickr
Nov 15 '18 at 15:22





You use the addfRow(...) method of the DefaultTableModel to add the row.

– camickr
Nov 15 '18 at 15:22












1 Answer
1






active

oldest

votes


















0














I resolved my problem with this, but now if i add new file my table is refreshed but they loose renderer view for jprogress bar and checkbox.
I need help.



 Path path = Paths.get(filePath.getAbsolutePath());
try
Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS);
if (!isFolder)
Log.error(this, "Path: " + path + " is not a folder");
throw new IllegalArgumentException("Path: " + path + " is not a folder");

System.out.println("Watching path: " + path);
WatchService watchService = path.getFileSystem().newWatchService();
path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

WatchKey key;
while ((key = watchService.take()) != null)
for (WatchEvent<?> event : key.pollEvents())
File files = filePath.listFiles();
customTableDataList.clear();
for (File file : files)
customTableData = new CustomTableData(file);
customTableDataList.add(customTableData);

customTableModel = new CustomTableModel(customTableDataList);


This resolve my problem, table is reloaded but view is not rendering.




 myTable.setModel(customTableModel);



If I remove above and adding (line below), view of my table is correct but only when I click in checkbox (table is reloaded).




 myTable = new Table(customTableModel);



 myTable.repaint();

System.out.println("#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());


//Log.info(this, "#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());
key.reset();

catch (IOException e)
e.printStackTrace();
catch (Exception e)
e.getMessage();






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314216%2fhow-to-listen-adding-a-new-file-to-a-folder-to-show-up-in-jtable%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I resolved my problem with this, but now if i add new file my table is refreshed but they loose renderer view for jprogress bar and checkbox.
    I need help.



     Path path = Paths.get(filePath.getAbsolutePath());
    try
    Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS);
    if (!isFolder)
    Log.error(this, "Path: " + path + " is not a folder");
    throw new IllegalArgumentException("Path: " + path + " is not a folder");

    System.out.println("Watching path: " + path);
    WatchService watchService = path.getFileSystem().newWatchService();
    path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

    WatchKey key;
    while ((key = watchService.take()) != null)
    for (WatchEvent<?> event : key.pollEvents())
    File files = filePath.listFiles();
    customTableDataList.clear();
    for (File file : files)
    customTableData = new CustomTableData(file);
    customTableDataList.add(customTableData);

    customTableModel = new CustomTableModel(customTableDataList);


    This resolve my problem, table is reloaded but view is not rendering.




     myTable.setModel(customTableModel);



    If I remove above and adding (line below), view of my table is correct but only when I click in checkbox (table is reloaded).




     myTable = new Table(customTableModel);



     myTable.repaint();

    System.out.println("#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());


    //Log.info(this, "#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());
    key.reset();

    catch (IOException e)
    e.printStackTrace();
    catch (Exception e)
    e.getMessage();






    share|improve this answer





























      0














      I resolved my problem with this, but now if i add new file my table is refreshed but they loose renderer view for jprogress bar and checkbox.
      I need help.



       Path path = Paths.get(filePath.getAbsolutePath());
      try
      Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS);
      if (!isFolder)
      Log.error(this, "Path: " + path + " is not a folder");
      throw new IllegalArgumentException("Path: " + path + " is not a folder");

      System.out.println("Watching path: " + path);
      WatchService watchService = path.getFileSystem().newWatchService();
      path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

      WatchKey key;
      while ((key = watchService.take()) != null)
      for (WatchEvent<?> event : key.pollEvents())
      File files = filePath.listFiles();
      customTableDataList.clear();
      for (File file : files)
      customTableData = new CustomTableData(file);
      customTableDataList.add(customTableData);

      customTableModel = new CustomTableModel(customTableDataList);


      This resolve my problem, table is reloaded but view is not rendering.




       myTable.setModel(customTableModel);



      If I remove above and adding (line below), view of my table is correct but only when I click in checkbox (table is reloaded).




       myTable = new Table(customTableModel);



       myTable.repaint();

      System.out.println("#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());


      //Log.info(this, "#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());
      key.reset();

      catch (IOException e)
      e.printStackTrace();
      catch (Exception e)
      e.getMessage();






      share|improve this answer



























        0












        0








        0







        I resolved my problem with this, but now if i add new file my table is refreshed but they loose renderer view for jprogress bar and checkbox.
        I need help.



         Path path = Paths.get(filePath.getAbsolutePath());
        try
        Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS);
        if (!isFolder)
        Log.error(this, "Path: " + path + " is not a folder");
        throw new IllegalArgumentException("Path: " + path + " is not a folder");

        System.out.println("Watching path: " + path);
        WatchService watchService = path.getFileSystem().newWatchService();
        path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

        WatchKey key;
        while ((key = watchService.take()) != null)
        for (WatchEvent<?> event : key.pollEvents())
        File files = filePath.listFiles();
        customTableDataList.clear();
        for (File file : files)
        customTableData = new CustomTableData(file);
        customTableDataList.add(customTableData);

        customTableModel = new CustomTableModel(customTableDataList);


        This resolve my problem, table is reloaded but view is not rendering.




         myTable.setModel(customTableModel);



        If I remove above and adding (line below), view of my table is correct but only when I click in checkbox (table is reloaded).




         myTable = new Table(customTableModel);



         myTable.repaint();

        System.out.println("#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());


        //Log.info(this, "#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());
        key.reset();

        catch (IOException e)
        e.printStackTrace();
        catch (Exception e)
        e.getMessage();






        share|improve this answer















        I resolved my problem with this, but now if i add new file my table is refreshed but they loose renderer view for jprogress bar and checkbox.
        I need help.



         Path path = Paths.get(filePath.getAbsolutePath());
        try
        Boolean isFolder = (Boolean) Files.getAttribute(path, "basic:isDirectory", NOFOLLOW_LINKS);
        if (!isFolder)
        Log.error(this, "Path: " + path + " is not a folder");
        throw new IllegalArgumentException("Path: " + path + " is not a folder");

        System.out.println("Watching path: " + path);
        WatchService watchService = path.getFileSystem().newWatchService();
        path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);

        WatchKey key;
        while ((key = watchService.take()) != null)
        for (WatchEvent<?> event : key.pollEvents())
        File files = filePath.listFiles();
        customTableDataList.clear();
        for (File file : files)
        customTableData = new CustomTableData(file);
        customTableDataList.add(customTableData);

        customTableModel = new CustomTableModel(customTableDataList);


        This resolve my problem, table is reloaded but view is not rendering.




         myTable.setModel(customTableModel);



        If I remove above and adding (line below), view of my table is correct but only when I click in checkbox (table is reloaded).




         myTable = new Table(customTableModel);



         myTable.repaint();

        System.out.println("#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());


        //Log.info(this, "#LIST: " + customTableDataList + " >>> #SIZE: " + customTableDataList.size());
        key.reset();

        catch (IOException e)
        e.printStackTrace();
        catch (Exception e)
        e.getMessage();







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 '18 at 12:32

























        answered Nov 20 '18 at 12:21









        PrzemekCPrzemekC

        813




        813





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314216%2fhow-to-listen-adding-a-new-file-to-a-folder-to-show-up-in-jtable%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo