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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:21:06+00:00 2026-06-16T13:21:06+00:00

I created a JDialog which I want to move and resize. My program draws

  • 0

I created a JDialog which I want to move and resize. My program draws JDialog on the screen. When the user clicks it, it should stretch to the width of the screen and then gain height. I tried it like this.

for(int i = 150; i <= width; i += 3) {
    dialog.setSize(i, 80);

    try {
        Thread.sleep(0, 1);
    } catch(Exception e2) {}
}

for(int i = 80; i <= 200; i++) {
    dialog.setSize(width, i);

    try {
        Thread.sleep(1);
    } catch(Exception e3) {}
}

When the code is executed, it will take a while and then the JDialog will be shown stretched immediately. No expanding is shown.

Well, when the user clicks the dialog again, it will reverse the opening animation and close.

for(int i = 200; i >= 80; i--) {
    newMsg.setSize(width, i);

    try {
        Thread.sleep(0, 1);
    } catch(Exception e4) {}
}   

for(int i = 0; i >= -width; i -= 3) {
    newMsg.setLocation(i, 100);

    try {
        Thread.sleep(0, 1);
    } catch(Exception e5) {}
}

This one works correctly. The movement is able to be seen. As far as I understand, these codes are otherwise identical except they are reversed. Why doesn’t the opening work as expected but the closing does?

  • 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-16T13:21:07+00:00Added an answer on June 16, 2026 at 1:21 pm

    Don’t call Thread.sleep in the EDT. This causes the UI to “freeze”. You could use a Swing Timer here instead. Here is how the initial “expand” might be handled::

    Timer timer = new Timer(0, new ActionListener() {
    
       @Override
       public void actionPerformed(ActionEvent e) {
        updateDialogSize();
       }
    });
    
    timer.setDelay(5); // short delay
    timer.start();
    

    Update dialog:

    void updateDialogSize() {
       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
       if (dialog.getWidth() < screenSize.getWidth()) { // 1st size width
          dialog.setSize(dialog.getWidth() + 5, dialog.getHeight());
       } else if (dialog.getHeight() < screenSize.getHeight()) { // then size height
         dialog.setSize(dialog.getWidth(), dialog.getHeight() + 5);
       } else {
          timer.stop(); // work done
       }
    
         dialog.setLocationRelativeTo(myFrame);
    }
    

    I’ll leave the dialog “contraction” as an excercise 😉

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

Sidebar

Related Questions

I have created a JDialog which displays two different tables. When the user selects
I am using NetBeans' GUI Designer to create some JDialog s, which I then
I want to add a button (JButton) at the bottom of a JDialog which
I have created a JDialog which contains a JLabel. Because the length of text,
I have created a JDialog which contains a JComboBox and a panel underneath which
Here is my problem. I created a JForm which should help to insert new
I have created a class which extends JDialog, where I have some checkboxes and
I have created a JDialog in NetBeans and a custom constructor as follows: public
I extended JDialog to create a custom dialog where the user must fill some
I created a JButton which has an image set as an icon representing the

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.