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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:44:55+00:00 2026-06-09T16:44:55+00:00

I have two JFrames jFrame1 and jFrame2 ,in jFrame1 there’s a textfield and a

  • 0

I have two JFrames jFrame1 and jFrame2,in jFrame1 there’s a textfield and a button,while clicking on button jFrame2 will appear. In jFrame2 there’s also a textfield and a button.I will type a name in textfield of jFrame2 and by clicking the button in it that textfield value should appear on textfield of jFrame1. But I am not getting the focus transferred to jFrame1,i tried the code,

in jFrame1

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        jFrame2 abc=new jFrame2();
        abc.setVisible(true);
    }   


public void inserting(String name){
   jTextField1.requestFocusInWindow();
   jTextField1.setText(name);

 }

in jFrame2,

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        jFrame1 abc1=new jFrame1();
       // abc1.transferFocus();  //not working

        abc1.inserting(jTextField1.getText());
        this.dispose();
    } 

I am getting value to the method inserting(),but it’s not getting set into the textfield. If I again give setVisible(true) for jFrame1 it works,but I dont want to do i in that way. Is there any other way to resolve this?

  • 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-09T16:44:56+00:00Added an answer on June 9, 2026 at 4:44 pm

    To bring focus to the field, you should use requestFocusInWindow, however I don’t think that will bring the window in question back into focus.

    You could use a WindowListener to monitor changes that you could respond.

    For example, in jFrame1‘s actionPerformed handler you could

    Frame02 frame2 = new Frame02();
    frame2.addWindowListener(new WindowAdapter() {
    
        @Override
        public void windowClosed(WindowEvent we) {
    
            Frame02 frame2 = (Frame02) we.getWindow();
            jTextField1.setText(frame2.getText());
    
            toFront();
            jTextField1.requestFocusInWindow();
    
        }
    
    });
    
    frame2.setVisible(true);
    frame2.toFront();
    frame2.requestFocus();
    

    jFrame1 is requesting the text from jFrame2 cause jFrame2 doesn’t know about jFrame1, there’s no reference to it.

    In jFrame2 you would need to add a WindowListener to handle the request for focus of the text field

    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent we) {
            jTextField1.requestFocus();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Jframes where frame1 has some text fields and when a button
so I have this jFrame with a Panel. Inside that panel there are two
I have two screens plugged into my computer and was wondering if there was
I have two forms. First one is to decide numbers of button by using
If I have two JFrames where one is the main JFrame, and the other
I have two JFrame Forms-SelectContactsfrm.java and Taskfrm.java. There is JTable in SelectContactsfrm file to
im creating a java application with netbeans. i have two jframes for login and
In my program I have two JFrame instances. When I click next button I
I have a portion of code that takes the text of a TextField (there
I'm using two frames. In the first frame I have a button to open

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.