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

  • Home
  • SEARCH
  • 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 8123509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:12:11+00:00 2026-06-06T06:12:11+00:00

When i am closing my JFileChooser dialog, it opens again. I’m using the libgdx

  • 0

When i am closing my JFileChooser dialog, it opens again. I’m using the libgdx update for checking the input.

Here is the input code…

if(!SaveDialog.open) {
    if(input.isKeyPressed(Input.Keys.S)) {
        SaveDialog.Save(pixmap);
    }
}

If I am pressing S very quickly, the dialog opens only one time, but if I am pressing it for like 2 sec, there will be a endless (I think) number of JFileChooser dialogs.

This is my code…

public class SaveDialog {
    private static boolean inited = false;
    private static JFileChooser fc;
    public static boolean open = false;

    public static void Init() {
        fc = new JFileChooser();

        fc.setFileFilter(new FileFilter() {
            public String getDescription() {
                return ".png";
            }
            public boolean accept(File f) {
                return f.getName().endsWith(".png");
            }
        });

        inited = true;
    }

    public static void Save(Pixmap pixmap) {
        open = true;

        if(!inited) {
            Init();
        }

        fc.showSaveDialog(null);

        byte[] data;
        try {
            data = PNG.toPNG(pixmap);
            FileHandle fh = new FileHandle(fc.getSelectedFile() + ".png");
            fh.writeBytes(data, false);
            open = false;
        }
        catch (IOException e) {
            open = false;
            e.printStackTrace();
        }
    }
}

Could someone please help me with this problem.

  • 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-06-06T06:12:13+00:00Added an answer on June 6, 2026 at 6:12 am

    It doesn’t help that isKeyPressed(Input.Keys.S) determines if the S key is currently held down.

    If you haven’t given libgdx a chance to poll the input again before isKeyPressed() is called for the second time then I suspect that it will still think that it is held down.

    If that isn’t the issue, try recording the key’s state and only open the dialog when it changes state from not pressed to pressed.

    For example:

    if(!SaveDialog.open) {
        boolean isSPressed = input.isKeyPressed(Input.Keys.S);
        if(!wasSpressed && isSPressed) {
            SaveDialog.Save(pixmap);
        }
        wasSPressed = isSPressed;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with closing saveFileDialog. when i click'cancel' window appears once again. here
How do I manage closing StreamReader and StreamWriter which are using the same underlying
I'm closing a WCF endpoint in the page_unload of an asp.net page, when using
I'm opening and closing dialogs that are dynamically created using ajax. I'd like to
I mean preventing any action closing-unloading-terminating they all should be prevented until the code
Is there a trac plugin for automatically closing tickets that have remained open for
Closing this question. Will drink red bull. Sleep. Code and come back with brand
Why are my Swing applications not closing when using Netbeans 6.5 on Ubuntu 8.10
I am having trouble closing jQuery Facebox from code behind. I am inserting a
What security issues can arise from not closing the database connection after using it?

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.