Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6752823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:05:23+00:00 2026-05-26T13:05:23+00:00

Launch a file = launch program associated with given file and automatically open that

  • 0

Launch a file = launch program associated with given file and automatically open that file on start of the program.

Let’s say I run IntelliJ IDEA, I run my code and main window (modal) of my program shows up. My program is in the foreground.

Then I launch a .pdf file (for now it means AcroReader will be executed) from my program. AA will show up in front of IntelliJ but behind my program.

Question

I would like AA (it is just an example here of course) to be shown in front of my program, not behind. How to do it?

Please note, this does not mean I would like to move my program to the background!

For launching files I use

java.awt.Desktop.getDesktop().open(new java.io.File(filepath));

My GUI is done in Swing.

Update 1

To rule out, any influence of custom widgets, events, and so on, I put simply JButton at the bottom of my window (JDialog) — it is in Scala, but this piece is similar to Java syntax:

var dlg = new javax.swing.JDialog(null,"test",Dialog.ModalityType.DOCUMENT_MODAL);
dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

var button = new JButton("Select Me");
var actionListener = new ActionListener() {
      def actionPerformed( actionEvent : ActionEvent) = {
        java.awt.Desktop.getDesktop().open(new java.io.File("test.pdf"))
      }
    };

button.addActionListener(actionListener);
dlg.add(button, BorderLayout.SOUTH);
dlg.setSize(300, 100);
dlg.setVisible(true);

Once clicked, AA is shown behind my app. Since it takes several seconds to run AA I also tried to click the button, and move the mouse away from my window. Exactly the same behaviour.

I also noted that AA is shown at the same relative position to my window, top left corner of AA is near bottom right corner of my app.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:05:23+00:00Added an answer on May 26, 2026 at 1:05 pm

    You may try something like this. On my machine (Ubuntu 10.4 LTS with Gnome2) it gives the evince (pdf-viewer) in the front, and if I close/hide evince – JDialog is placed back to the front.

    On windows it may be very different, since actually without “dlg.toBack();” invocation behavior is the same.

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.SwingUtilities;
    import javax.swing.WindowConstants;
    
    public class OpenFileTest {
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                final JDialog dlg = new javax.swing.JDialog(null, "test", JDialog.ModalityType.DOCUMENT_MODAL);
                dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                JButton button = new JButton("Select Me");
                button.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            java.awt.Desktop.getDesktop().open(
                                    new java.io.File("/home/user/Downloads/jfreechart-1.0.13-US.pdf"));
                            dlg.toBack();
                        } catch (IOException e1) {
                            throw new RuntimeException(e1);
                        }
                    }
                });
                dlg.add(button);
                dlg.setVisible(true);
            }
        });
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It am trying to launch this code that would normally run from a batch
I want to launch a file(a document) from a Java program and phase the
Suppose I have a source file open and I launch a shell. I can
I need to open an html file from the program root directory and have
There's an open source program called CIMCheck ( http://wiki.cimtool.org/CIMCheck.html ) that is supposed to
I'm using the ShellExecuteEx function in a C++ program to launch an Uninstall.lnk file.
i have a command line executable program that accepts a configuration file as it's
I want to create a manifest file for my VB 6.0 program, so that
I have a python program that uses subprocess.Popen to launch another process (python process
I have a Windows program that needs to update itself from a server automatically.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.