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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:59:10+00:00 2026-06-14T01:59:10+00:00

i have a Jframe (Mainz), it have a button (showDialog), when user click the

  • 0

i have a Jframe (Mainz),

it have a button (showDialog),

when user click the button,

jdialog (Dialogz) will show,

that jdialog have a button

  • how to close jdialog from that button (inside jdialog)?
  • can i change the modal of dialog after i create instance of it?

i need to block the owner of that jdialog

heres i try …

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;


    public class Mainz extends JFrame implements ActionListener{
        JButton showDialog = new JButton("show dialog");

        public Mainz() {
            setLayout(new FlowLayout());
            showDialog.addActionListener(this);
            add(showDialog);
            setVisible(true);   
        }
        @Override
        public void actionPerformed(ActionEvent e) {
            new Dialogz(this, true);
        }

        public static void main(String[]args){
            new Mainz();
    }
    }
    class Dialogz extends JDialog{
        JButton close = new JButton("close");

        public Dialogz(JFrame owner,boolean modal) {
            super(owner, modal);
            System.out.println(this.getModalityType());
            add(close);
            setLocationRelativeTo(owner);
            setVisible(true);

            close.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae){
                    closez();
                }
            });
        } 

        void closez(){
            setModal(false);
            this.dispose();
            System.out.println("Method Done");

        }
    }

thanks a lot for any kind of help

  • 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-14T01:59:11+00:00Added an answer on June 14, 2026 at 1:59 am

    can i change the modal of dialog after i create instance of it?

    yes you can to change setModal or ModalityTypes on runtime, but for code in this form doesn’t make me any sence

    how to close jdialog from that button (inside jdialog)?

    in this case doesn’t matter if you’ll to call setVisible or dispose()


    • create JDialog only one time,

    • create that as local variable

    • change myDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);, then button in the toolbar (with X) to hide JDialog too

    • then you can to call from actionPerformed only myDialog.setVisible(true) and ModalityType too if required, setVisible shoud be wrapped in invokeLater(), instead of creating a new instance (new Dialogz(this, true); )

    • JButton placed in JDialog will be called only myDialog.setVisible(false)

    • example corresponding with your logics

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

Sidebar

Related Questions

I have created a text field component with an 'x' button inside that will
I have a JFrame and I open a JDialog from it and another JDialog
I have a main JFrame. There is a button inside the frame. When I
I have a main JFrame that is interactive, i.e. user sets different options. After
I have class main extends jframe , it has a button that calls /shows
I have a JDialog dlg, created by a JFrame frm, that contains a JList
I have a Jframe window inside which there is a button. By clicking the
I have a JFrame which on instantiation calls a custom JDialog(Login). If login is
I have a JFrame with JScrollPane in it. I have JPanel inside a scrollPane.
I have a main jFrame with the help of which i press button and

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.