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 3359262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:51:03+00:00 2026-05-18T02:51:03+00:00

I have a button in my program that, when pressed, is supposed to take

  • 0

I have a button in my program that, when pressed, is supposed to take you to my wiki page about the program. I used the following line to do so:

java.awt.Desktop.getDesktop().browse(new java.net.URI("http://supuh.wikia.com/wiki/BHT"));

The problem is that, no matter what environment in which the program is run, I always get the following error:

java.security.AccessControlException: access denied (java.awt.AWTPermission showWindowWithoutWarningBanner)

does anyone know how I can fix this? Note that this only works in the one program. Any other program I make can use the same method with no problem.

Exit hook


At the start of my program, this hook is added. The program runs fine without it…

System.setSecurityManager(new SecurityManager()
{
  @Override
  public void checkExit(int status)
  {
    closeFile(status);
  }
});

this hook is needed, but the browse(URI uri) method in question won’t work with it. Solutions?

  • 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-18T02:51:04+00:00Added an answer on May 18, 2026 at 2:51 am

    This means you are running with a security manager:

    SecurityException – if a security manager exists and it denies the AWTPermission("showWindowWithoutWarningBanner") permission, or the calling thread is not allowed to create a subprocess; and not invoked from within an applet or Java Web Started application

    If this is an applet, or a Java Web Start app – sign your jar.

    Update Adding a security manager to detect program exit is wrong. There are multiple ways to do this properly. In your case I guess this would be most appropriate:

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
          @Override
          public void run() {
             closeFile();
          }
    ));
    

    Swing-specific solutions are:

    • if you don’t have to perform extra actions, use frame.setDefaultCloseAction(Frame.EXIT_ON_CLOSE)

    • use addWindowStateListener and check for WindowEvent.WINDOW_CLOSED

    That said, two notes:

    • you must not hold files open for a long time. Use try/catch/finally to open and close them whenever they are needed.

    • if you really need a security manager at some point, make sure you override the appropriate method of the SecurityManager that checks whether you can open the link. (won’t tell you which one, so that you are not tempted to jump onto this solution, which is wrong)

    To summarize, I’d go for setDefaultActionOnClose, and close each file right after I finish reading/writing it.

    Update 2: After you linked to your original question describing what exactly are you trying to achieve, things change a bit. You are trying to prevent exit, so you do need a SecurityManager. This makes it so that you should override the checkPermission method and do nothing there (i.e. don’t throw exceptions), at least when these permissions are checked (they are checked when browse is called):

    • new AWTPermission("showWindowWithoutWarningBanner")
    • new FilePermission("<<ALL FILES>>", SecurityConstants.FILE_EXECUTE_ACTION)

    Update 3 Here’s how exactly to override the method:

    @Override
    public void checkPermission(Permission permission) {
       if (permission instanceof AWTPermission) {
           if (permission.getName().equals("showWindowWithoutWarningBanner")) {
               return;
           }
       }
     
       if (permission instanceof FilePermission) {
           if (permission.getActions().equalsIgnoreCase("execute")) {
              return;
           }
       }
    
       java.security.AccessController.checkPermission(permission);
    }
    

    (you can go without the outer if-s)

    Update 4 The above method will work only if you have given permissions to your program. Otherwise it is a not-well documented behaviour of the JVM that overriding security managers are not allowed to be unprivileged. Take a look at this report – the comments say how to work it around.

    To make your life simpler, you can simply @Override public void checkPermission(..) with an empty method body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button on an ASP.Net page that will call Response.Redirect back to
I need to have a physical button that when pressed will be noticed by
I have a Delphi program that creates HTML files. Later when a button is
I have a button that I would like to disable when the form submits
We have a button that saves asynchronously using AjaxToolKit/C#/.NET. I'm getting this in my
I have a button on a website that creates a directory and copys a
I have a Button that is looking at 2 comboboxes to make sure they
Say I have simple program that emulates a board game with a number of
I have a program that adds LineItems to a ZedGraph pane whenever data parameters
I have a program that can open multiple forms, and when there are a

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.