• Post Reply Bookmark Topic Watch Topic
  • New Topic

looping just before or on showing file chooser  RSS feed

 
Nigel Hoath
Greenhorn
Posts: 19
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a looping standalone gui Java animal developed using Eclipse EE under Windows. I'll try to illustrate here the problem. The code is rather large to show it all but I can illustrate one line of code that creates the problem. Hopefully the issue is known or might ring bells with someone.

My program works fine. I want to add new functionality based on a SWT tree. The SWT tree seems a real pain to use so decided to switch to swing JTree.

To get started I add the following code near the top where I create a load of objects.




When I run it I have no errors and in the console I see "actiontree1" along with all normal logging.

The app displays and I choose 'file/import' after which I expect a file chooser to be displayed. But the program loops. The code:



The console shows:

  • actiontree1
    menu - Import clicked
    import trying jfile chooser
    import trying jfile chooser2
    import trying jfile chooser3


  • And the app is looping.

    But if I comment out the JTree create, as below, everything is fine.



    The app does absolutely nothing with the JTree. It is only referenced in the lines you see. I've run this in both versions many times with same result.

    Any thoughts??? Cheers and thanks for looking
     
    Campbell Ritchie
    Marshal
    Posts: 56536
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I know next to nothing about trees, but I do know about file choosers.
    You do not usually need to create a new file chooser obect; you can declare it outside your loop and then call methods like show open dialogue and show save dialogue.
    The dialogue returns an int depending on whether you have chosen a file or not. You don't use the file chooser in a standalone statement, but inside a loop or an ifIn that example, the opening of the dialogue window and your choosing the file all take place inside the () after while.

    That code is doubtless full of spelling errors, but you will find the right way to do it in the Java Tutorials. If you tell the dialogue to appear on top of itself, which you are doing by passing the chooser to its own method as an argument, where does the dialogue appear?
    If you pass null, it works without a GUI but the dialogue may appear in the centre of the screen, but behind something else. It may take some finding: minimise everything else if it isn't obvious.
     
    Campbell Ritchie
    Marshal
    Posts: 56536
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As for the Java Tutorials, have you seen this section?
     
    Nigel Hoath
    Greenhorn
    Posts: 19
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell many thanks for that. The code will be useful once I get beyond proto-type stage.

    And many many thanks for defining the problem. The filechooser was indeed hidden. Thus the problem is not looping.

    But this raises two questions:

    1/. Why should the line: JTree actiontree1 = new JTree(); upset the display of a file chooser?
    2/. How do you force the filechooser to be on top? (which is where it always appears - hundreds of runs at various development stages - without the JTree statement.)

    But at least now I can press on with replacing SWT tree with swing JTree.
     
    Campbell Ritchie
    Marshal
    Posts: 56536
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You usually cause pop‑ups (officially called dialogues) to appear in front of a Swing/AWT (not that anybody still uses AWT) component, by passing a reference to that component to the showXXXDialog method. If you do not have any GUI at all, pass null.
    There should be something about dialogues in the Java Tutorials. That section is mostly about JOPtionPane, so be sure to go through its methods, particularly those with names starting show. The same sort of thing applies to file choosers.

    No idea about the tree constructor call, I am afraid.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!