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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:42:27+00:00 2026-06-01T03:42:27+00:00

Basically, I have somewhere in my main code where this line of code is

  • 0

Basically, I have somewhere in my main code where this line of code is called

editwindow clubeditwindow = new editwindow(1,"Club Edit");

This line opens a new JFrame that can basically edit a bunch of information from the main class. I have 2 buttons called save and cancel. When save is clicked, I want to take the values from the textfields and then put it into a new object and return that to the main class, and close the window. When cancel is clicked, I want it to just not do anything, which is simple enough.

Thanks in advance.

  • 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-01T03:42:28+00:00Added an answer on June 1, 2026 at 3:42 am

    Don’t display the window as a JFrame but rather display it as a modal dialog. Then after it is no longer visible, the main GUI can query the object for any information that it holds. The simplest way to do this is to use a JOptionPane — they are clever little beasts if used correctly.

    Here’s an example of what I mean. The JOptionPane holds JPane that displays information using a GridBagLayout.

    ComplexOptionPane.java: displays the main JFrame.

    import java.awt.event.*;
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class ComplexOptionPane extends JPanel {
       private PlayerEditorPanel playerEditorPanel = new PlayerEditorPanel();
       private JTextArea textArea = new JTextArea(20, 40);
    
       public ComplexOptionPane() {
          add(new JScrollPane(textArea));
          add(new JButton(new AbstractAction("Get Player Information") {
    
             @Override
             public void actionPerformed(ActionEvent arg0) {
                int result = JOptionPane.showConfirmDialog(null, playerEditorPanel,
                      "Edit Player", JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.PLAIN_MESSAGE);
                if (result == JOptionPane.OK_OPTION) {
                   for (PlayerEditorPanel.FieldTitle fieldTitle : 
                      PlayerEditorPanel.FieldTitle.values()) {
                      textArea.append(String.format("%10s: %s%n", fieldTitle.getTitle(),
                            playerEditorPanel.getFieldText(fieldTitle)));
                   }
                }
             }
          }));
       }
    
       private static void createAndShowGui() {
          ComplexOptionPane mainPanel = new ComplexOptionPane();
    
          JFrame frame = new JFrame("ComplexOptionPane");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(mainPanel);
          frame.pack();
          frame.setLocationByPlatform(true);
          frame.setVisible(true);
       }
    
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                createAndShowGui();
             }
          });
       }
    }
    

    PlayerEditorPanel.java which holds the JPanel that is displayed in a JOptionPane

    import java.awt.*;
    import java.util.HashMap;
    import java.util.Map;
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    class PlayerEditorPanel extends JPanel {
       enum FieldTitle {
          NAME("Name"), SPEED("Speed"), STRENGTH("Strength");
          private String title;
    
          private FieldTitle(String title) {
             this.title = title;
          }
    
          public String getTitle() {
             return title;
          }
       };
    
       private static final Insets WEST_INSETS = new Insets(5, 0, 5, 5);
       private static final Insets EAST_INSETS = new Insets(5, 5, 5, 0);
       private Map<FieldTitle, JTextField> fieldMap = new HashMap<FieldTitle, JTextField>();
    
       public PlayerEditorPanel() {
          setLayout(new GridBagLayout());
          setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Player Editor"),
                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
          GridBagConstraints gbc;
          for (int i = 0; i < FieldTitle.values().length; i++) {
             FieldTitle fieldTitle = FieldTitle.values()[i];
             gbc = createGbc(0, i);
             add(new JLabel(fieldTitle.getTitle() + ":", JLabel.LEFT), gbc);
             gbc = createGbc(1, i);
             JTextField textField = new JTextField(10);
             add(textField, gbc);
    
             fieldMap.put(fieldTitle, textField);
          }
       }
    
       private GridBagConstraints createGbc(int x, int y) {
          GridBagConstraints gbc = new GridBagConstraints();
          gbc.gridx = x;
          gbc.gridy = y;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
    
          gbc.anchor = (x == 0) ? GridBagConstraints.WEST : GridBagConstraints.EAST;
          gbc.fill = (x == 0) ? GridBagConstraints.BOTH
                : GridBagConstraints.HORIZONTAL;
    
          gbc.insets = (x == 0) ? WEST_INSETS : EAST_INSETS;
          gbc.weightx = (x == 0) ? 0.1 : 1.0;
          gbc.weighty = 1.0;
          return gbc;
       }
    
       public String getFieldText(FieldTitle fieldTitle) {
          return fieldMap.get(fieldTitle).getText();
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the same question as this guy .. The example in the
I've been pulling my hair out on this one all afternoon. Basically, I have
Basically, I have lots of differently typed structs like this: typedef struct { char
I basically have a unix process running and it is doing some heavy processing
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have 7 select statements that I need to have the results output
I basically have to do a update of a record. I have a set
I basically have to write a clone of the UNIX ls command for a

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.