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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:56:41+00:00 2026-06-14T18:56:41+00:00

I have tried to create an exception that throws up dialogue box and stop

  • 0

I have tried to create an exception that throws up dialogue box and stop the user from resizing a jframe any smaller than (250, 350) but I have had no luck in doing so.

So my question is, if I have a Jframe pane with the set size of 800, 500. Can I create an exception that when the user tries to make the jframe smaller than a certain size, it stops them at that size and shows a error message?

  • 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-14T18:56:42+00:00Added an answer on June 14, 2026 at 6:56 pm

    Don’t create an exception. Create an action Listener that throws an Error Message in the form of a JOptionPane Dialog Box when the user resizes the window to any size smaller than (250, 350)

    Here is the running Code for you, Enjoy !

        import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.Timer;
    
    public class Resize {
    
        Resize(){
    
    
        final JFrame frame = new JFrame();
        frame.setBounds(100, 50, 500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        frame.getContentPane().setBackground(Color.white);
    
    
        frame.setVisible(true);
        ActionListener al = new ActionListener() {
    
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                if(frame.getSize().width <250 || frame.getSize().height <350)
                {
                    JOptionPane.showMessageDialog(null, "Size cannot be smaller than 250,350"); 
                    frame.setSize(500, 500);
                }
            }
        };
    
        Timer t = new Timer(1000, al);
        t.start();
    
        }
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            new Resize();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried create this table, but nothing I have tried works from FKs.
I have tried to create a simple controller/model (based on the samples code of
We have tried to create sample webservices helloworld in Java using Jersey and Tomcat
I have tried with ado.net create table columnName with unique name. as uniquename I
Have anybody ever tried to create thumbnails/previews of MS Office files? I do not
I have tried FBConnect for iPhone and am able to create/manage sessions and upload
Hi I want to create a JSON array. I have tried using: JSONArray jArray
I have a SQL Server Stored Procedure that looks like this: CREATE PROCEDURE [dbo].[my_stored_procedure]
I have a large Hg repository (2+GB) that was converted from an svn repository.
I have a superclass called Canvas, from which I create several subclasses. I want

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.