Results 1 to 10 of 10
  1. #1
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default How to make JFileChooser always on top?

    Hi, I'm currently making a program to receive file.
    When a request to receive file arrived, a JOptionPane popped up to get user input(accept or reject).
    If the user choose accept then a JFileChooser will be popped up and the user can choose the directory to save.

    The problem is while the user is choosing the file, if there's new request arrived, the JOptionPane will block the JFileChooser.

    What I tried:
    1. Insert JOptionPane into modeless JDialog, it failed because it also block the JFileChooser.
    2. Making modeless JDialog like JOptionPane, it failed because I don't know how to pass 'accept' button parameter and to make receiver to wait for the choose action.
    3. Override createDialog of JFileChooser and change the ModalityType, it failed because JOptionPane still block the JFileChooser

    I tried to override JOptionPane but don't know how to do it.

    To summary it, I want to make either JFileChooser always on top or make JOptionPane not to block the JFileChooser.
    I want to prevent the blocking to happen, can someone provide a solution?

    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    What event causes the display of the JOptionPane? When you show the JFileChooser, are you passing a parent Component to the showOpenDialog method?

  3. #3
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    What event causes the display of the JOptionPane? When you show the JFileChooser, are you passing a parent Component to the showOpenDialog method?
    I have something like request file listener that triggers the JOptionPane, if a request come, it calls the JOptionPane.

    Yes I pass the parent component to the method.
    Java Code:
    status = saveChooseDialog.showSaveDialog(anchorFrame);
    Sorry I forgot to mention, I make the JOptionPane to appear on taskbar using this trick.
    How can I make JOptionPane dialogs show up as a task on the taskbar? - Stack Overflow

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by LeonLanford View Post
    I have something like request file listener that triggers the JOptionPane, if a request come, it calls the JOptionPane.
    I'm not familiar with a request file listener, but would it be possible to use some logic in the listener to place the requests in a queue while the file chooser is active, and then display the requests in JOptionPanes after the JFileChooser closes?

    Sorry I forgot to mention, I make the JOptionPane to appear on taskbar using this trick.
    How can I make JOptionPane dialogs show up as a task on the taskbar? - Stack Overflow
    So the JOptionPanes are not tied to the main GUI?

    Edit: the last point doesn't matter.
    Last edited by Fubarable; 08-12-2010 at 06:11 PM.

  5. #5
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I'm not familiar with a request file listener, but would it be possible to use some logic in the listener to place the requests in a queue while the file chooser is active, and then display the requests in JOptionPanes after the JFileChooser closes?


    So the JOptionPanes are not tied to the main GUI?

    Edit: the last point doesn't matter.
    I'm making a messenger using Smack API, the listener is provided by the API.

    I'm also thinking about using queue system but I don't know how to put the request into queue :(
    If I put the request in queue then I need to check the queue periodically?

  6. #6
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    The problem is while the user is choosing the file, if there's new request arrived, the JOptionPane will block the JFileChooser.
    Have you tried to do it with threads?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by cselic View Post
    Have you tried to do it with threads?
    Even with threads, you'll have to collect the receive file arrive requests and then display them on the EDT once the JFileChooser has been dealt with. In my mind you'll likely want to deal with them in a FIFO basis, and thus a Queue.

  8. #8
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by cselic View Post
    Have you tried to do it with threads?
    Yes, I already put every request from the listener in their own thread.

    ------

    Thanks for the replies.. I'll figure out how to use queue in java :D

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Quote Originally Posted by LeonLanford View Post
    Hi, I'm currently making a program to receive file.
    When a request to receive file arrived, a JOptionPane popped up to get user input(accept or reject).
    If the user choose accept then a JFileChooser will be popped up and the user can choose the directory to save.

    The problem is while the user is choosing the file, if there's new request arrived, the JOptionPane will block the JFileChooser.
    Without seeing any code, I can only hazard a guess. Maybe you can do something like this.
    Java Code:
    public class DelayOptionPane {
    
      JFileChooser chooser = new JFileChooser();
      Timer timer = new Timer(250, new ActionListener() {
    
        @Override
        public void actionPerformed(ActionEvent e) {
          if (!chooser.isShowing()) {
            timer.stop();
            JOptionPane.showMessageDialog(null, "Option Pane");
          }
        }
      });
    
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            new DelayOptionPane().makeUI();
          }
        });
      }
    
      public void makeUI() {
        timer.start();
        chooser.showOpenDialog(null);
      }
    }
    db

  10. #10
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    Well you are using some kind of client/server programming.
    There are class processbuilder for operating system processes.

    I think (maybe this is wrong) that if you are familiar with C you should use in java something like "fork" in C for managing processes.

    I think that java.lang.ProcessBuilder might be useful for your problem.

Similar Threads

  1. Jfilechooser
    By greatmajestics in forum Java 2D
    Replies: 5
    Last Post: 03-30-2010, 06:13 PM
  2. help with JFileChooser
    By morgatron in forum New To Java
    Replies: 1
    Last Post: 01-08-2010, 09:00 AM
  3. using jfilechooser
    By jagadhguru in forum AWT / Swing
    Replies: 3
    Last Post: 10-30-2008, 12:17 PM
  4. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 05:40 PM
  5. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •