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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:32:13+00:00 2026-05-27T17:32:13+00:00

How to resize the height of JWindow from JButton actions (i tried setSize and

  • 0

How to resize the height of JWindow from JButton actions (i tried setSize and repaint but it does not work) ?

public class Gui extends JWindow implements KeyListener
{
  public static Gui mystatic;  
  private static JPanel panelBgImg;
  private final Dimension screen;
  public static int w = 0;
  public static int h = 0;

  public void paintComponent(Graphics g) 
  {
  }

  public Dimension getPreferredSize() 
  {      
      return new Dimension(100, h);
  }

  public Gui()
  {
    ....

    /* Button 1 */
    JButton jb2 = new JButton("")  
    {
        public Dimension getPreferredSize() 
        {
          return new Dimension(50,50);
        }            
    };
    jb2.setOpaque(false);
    jb2.setContentAreaFilled(false);
    jb2.setBorderPainted(false);

    jb2.addActionListener(new ActionListener() 
    {                
      public void actionPerformed(ActionEvent e) 
      {
         h = 100;         
         /* HERE i am trying to resize the JWindow itself but not working
               return new Dimension(100, h); */
         mystatic.setSize(screen.width, 100);
         mystatic.repaint();
      }
    });

    ...

}
  • 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-27T17:32:13+00:00Added an answer on May 27, 2026 at 5:32 pm

    for example

    please don’t use Thread.sleep(int) durring EDT, as demonstrated in this code example, there is used for closing current JVM instance, otherwise this instance never gone from PC’s RAM

    import java.util.logging.*;
    import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    
    public class SSCCE {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    
        private static void createAndShowGUI() {
            final JWindow window = new JWindow();
            final JPanel windowContents = new JPanel();
            JLabel label = new JLabel("A window that is pushed into view..........");
            windowContents.add(label);
            window.add(windowContents);
            window.pack();
            window.setLocationRelativeTo(null);
            final int desiredWidth = window.getWidth();
            window.getContentPane().setLayout(null);
            window.setSize(0, window.getHeight());
            window.setVisible(true);
            Timer timer = new Timer(15, new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    int newWidth = Math.min(window.getWidth() + 1, desiredWidth);
                    window.setSize(newWidth, window.getHeight());
                    windowContents.setLocation(newWidth - desiredWidth, 0);
                    if (newWidth >= desiredWidth) {
                        ((Timer) e.getSource()).stop();
                        //restore original layout
                        window.getContentPane().setLayout(new BorderLayout());
                        window.validate();
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(SSCCE.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        System.exit(0);
                    }
                }
            });
            timer.start();
        }
    
        private SSCCE() {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JFrame.setResizable(true) lets the user resize both the width and height of a window. Does
Ok. So I'm using the following code to resize a divs height, but as
I need to resize the cell height based on the content size/length.tried several methods,
A user is not allowed to resize a TextBox control vertically. The height of
How can I resize the height of a ListView depending on how many items
I want to resize cell's height according to the label's height and label's height
A current jQuery project of mine requires browser resize (width AND height) functionality, some
Can i resize images in python to given height and width,i use python 2.5,
When i resize my window then alert width and height then again resize my
I need to resize and crop an image to a specific width and height.

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.