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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:14:50+00:00 2026-05-15T11:14:50+00:00

I am new to the whole Java Swing/AWT dialogs (which explains how amateurish this

  • 0

I am new to the whole Java Swing/AWT dialogs (which explains how amateurish this dialog below looks like, any help in arranging it better is welcome 🙂 and I am struggling to close this popUp window when any of the two JButtons are clicked.

I have already tried options like frame.dispose(), frame.setVisible(false) and even SwingUtilities.getWindowAncestor(this).dispose();

Again, this is a secondary popup window invoked by another main process running, so I just want this particular popUp window to close and not affect the main process. Otherwise I could use System.exit

Like I mentioned, any other suggestions to improve the overall look and feel of the dialog are appreciated.

My entire code is as below:

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class UpgradePopupWindow extends JPanel implements ActionListener {
  public static UpgradePopupWindow mainWindow;

  static final long serialVersionUID = 0;

  final String upgrade = "Continue Upgrade";
  final String restore = "Restore";

  JPanel panels;
  JButton flashMe;
  JButton helpMe;
  JTextArea Message;
  JFrame frame;

  protected JTextArea addText(String text, boolean visible, int fontStyle) {
    JTextArea textArea = new JTextArea(text);

    textArea.setFont(new Font("SansSerif", fontStyle, 12)); //$NON-NLS-1$

    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);
    textArea.setForeground(Color.WHITE);
    textArea.setOpaque(false);
    textArea.setVisible(visible);
    textArea.setAlignmentX(Component.CENTER_ALIGNMENT);

    add(textArea);

    return textArea;
  }

  public UpgradePopupWindow(Object ft) {
    String text = "This is the random text for now. I will bother about the actual content later";
    addLabel(text, Font.PLAIN, 12);

    flashMe = new JButton(upgrade);
    flashMe.setActionCommand("upgrade");
    flashMe.addActionListener(this);
    flashMe.setEnabled(true);
    add(flashMe);


    helpMe = new JButton(restore);
    helpMe.setActionCommand("restore");
    helpMe.addActionListener(this);
    helpMe.setEnabled(true);
    add(helpMe);
  }

  protected JLabel addLabel(String text, int fontStyle, int size) {
    JLabel label = new JLabel(text);
    label.setFont(new Font("SansSerif", fontStyle, size)); 
    label.setAlignmentX(Component.CENTER_ALIGNMENT);
    label.setOpaque(false);
    label.setVisible(true);
    label.setForeground(Color.BLUE);

    add(label);
    return label;
  }

  public void createGUI(Object obj) {
    //Create and set up the frame.
    frame = new JFrame("PopUp Dialog");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //create and setup the content pane
    UpgradePopupWindow popUpContentPane = new UpgradePopupWindow(obj);

    popUpContentPane.setOpaque(true);
    frame.setContentPane(popUpContentPane);

    frame.pack();
    frame.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if("restore".equals(e.getActionCommand())) {
      System.out.println("restore button selected");
      frame.dispose();
      SwingUtilities.getWindowAncestor(this).dispose();
    } else if ("upgrade".equals(e.getActionCommand())) {
      System.out.println("upgrade button selected");
      frame.dispose();
    }
  }
}
  • 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-15T11:14:50+00:00Added an answer on May 15, 2026 at 11:14 am

    The problem is that your createGUI method is not static. So I imagine you are creating first a UpgradePopupWindow, calling createGUI on that, which in turn creates a enw UpgradePopupWindow.

    Try this instead:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class TempTest
    {
        public static void main(String[] args)
        {
            UpgradePopupWindow.createGUI(null);
        }
    }
    
    
    class UpgradePopupWindow extends JPanel implements ActionListener {
      public static UpgradePopupWindow mainWindow;
    
      static final long serialVersionUID = 0;
    
      final String upgrade = "Continue Upgrade";
      final String restore = "Restore";
    
      JPanel panels;
      JButton flashMe;
      JButton helpMe;
      JTextArea Message;
        JFrame frame;
    
    
        protected JTextArea addText(String text, boolean visible, int fontStyle) {
        JTextArea textArea = new JTextArea(text);
    
        textArea.setFont(new Font("SansSerif", fontStyle, 12)); //$NON-NLS-1$
    
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setEditable(false);
        textArea.setForeground(Color.WHITE);
        textArea.setOpaque(false);
        textArea.setVisible(visible);
        textArea.setAlignmentX(Component.CENTER_ALIGNMENT);
    
        add(textArea);
    
        return textArea;
      }
    
      public UpgradePopupWindow(JFrame frm, Object ft2) {
        String text = "This is the random text for now. I will bother about the actual content later";
        addLabel(text, Font.PLAIN, 12);
          frame = frm;
        flashMe = new JButton(upgrade);
        flashMe.setActionCommand("upgrade");
        flashMe.addActionListener(this);
        flashMe.setEnabled(true);
        add(flashMe);
    
    
        helpMe = new JButton(restore);
        helpMe.setActionCommand("restore");
        helpMe.addActionListener(this);
        helpMe.setEnabled(true);
        add(helpMe);
      }
    
      protected JLabel addLabel(String text, int fontStyle, int size) {
        JLabel label = new JLabel(text);
        label.setFont(new Font("SansSerif", fontStyle, size));
        label.setAlignmentX(Component.CENTER_ALIGNMENT);
        label.setOpaque(false);
        label.setVisible(true);
        label.setForeground(Color.BLUE);
    
        add(label);
        return label;
      }
    
      public static void createGUI(Object obj) {
        //Create and set up the frame.
        JFrame frame = new JFrame("PopUp Dialog");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //create and setup the content pane
        UpgradePopupWindow popUpContentPane = new UpgradePopupWindow(frame, obj);
    
        popUpContentPane.setOpaque(true);
        frame.setContentPane(popUpContentPane);
    
        frame.pack();
        frame.setVisible(true);
      }
    
      public void actionPerformed(ActionEvent e) {
        if("restore".equals(e.getActionCommand())) {
          System.out.println("restore button selected");
          frame.dispose();
          SwingUtilities.getWindowAncestor(this).dispose();
        } else if ("upgrade".equals(e.getActionCommand())) {
          System.out.println("upgrade button selected");
          frame.dispose();
        }
      }
    
    }
    

    The main change is that the createUI is static, and the UpgradePopupWindow takes the frame in the constructor.

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

Sidebar

Related Questions

I am fairly new to programming and while doing a lot of reading this
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new
I am looking for some guideline for my new application while choosing ORM. I
I new to Scrum and while I understand the team concept behind the Sprints,
While developing a new query at work I wrote it and profiled it in
I am new to UserControls, and while developing my own control I found a
I was working with a new C++ developer a while back when he asked
I am fairly new to using infragistics controls (started yesterday). While they are (very)
How can I find what's hanging all new installations on a Windows box? While
New class is a subclass of the original object It needs to be php4

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.