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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:45:50+00:00 2026-06-07T02:45:50+00:00

Please allow me to explain what I am trying to do – I think

  • 0

Please allow me to explain what I am trying to do – I think that the title explains it roughly, but I am none too sure that I am going about things the right way, so please correct me if I am wrong!

I have created a custom dialog using a LayeredPane. Essentially a jPanel is shown on the POPUP_LAYER, thus appearing over the top of the main content. This panel contains a simple ‘label-textbox-okay-cancel’ group of controls. I will call this the ‘Dialog Panel’.

What am I trying to do:
When a button is clicked on the main window (contained within the LayeredPane), the Dialog Panel will appear and allow the user to enter some text, then click okay or cancel. This is all easy enough, but I would like this code to be re-usable, which means that other buttons on the main window will invoke the same Dialog Panel, but with different text in the label.

This of course requires me to include some kind of callback function so that the okay button on the Dialog Panel will run the correct code, according to the button which invoked it.

My current attempt is to store a string which will contain the name of the function that should be run when the user clicks the okay button on the Dialog Panel. I am attempting to retrieve this string and convert it into the function name and so far I have found many references to ‘Reflection’, many of them suggesting that it is not a good idea.

In any case I have been unable to get any example code to work because I do not understand what the ‘obj’ is in the code below and am unable to invoke the method:

method = obj.getClass().getMethod(myCallbackString);

My questions are:

Firstly, am I even going about this the right way? I am more than open to suggestions, but please try to keep it as simple as possible because I really am just getting started!

Secondly, what is the ‘obj’ in the code shown above? I would really like to know, even if this is not the way that I should be doing things!

My other thoughts include: Should my Dialog Panel be in its own class, and if so, again, how to pass the callback function?

Any help or advice would be gratefully received.

BTW: In answer to the question “why not use a normal dialog?” I can only say that I am currently experimenting, and I simply want to see if I can do this!

MVK

  • 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-07T02:45:53+00:00Added an answer on June 7, 2026 at 2:45 am

    obj names the object whose method you want to call, in your case you can probably replace it with this (or drop it out entirely, since this is implied):

    private void callByName(String name) { 
      try { getClass().getMethod(name).invoke(this); }
      catch (RuntimeException e) { throw e; }
      catch (Exception e) { throw new RuntimeException(e); }
    }
    

    For this to work you need to declare a public no-arg method with the appropriate name.

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

Sidebar

Related Questions

Please allow me to explain what I have and what I am trying to
To keep things simple, please allow the assumption that some code requires the use
Hopefully I can explain this well enough, but please let me know if more
I know this sounds kind of vague, but please let me explain- I'm starting
Sorry guys, it seems like I didn't explain my question clearly. Please allow me
Can somebody please explain me why the kernel doesn't allow us to make a
Why C++ standard allow object slice ? Please don't explain c++ object slice concept
Please excuse the poorly worded title, hopefully I can explain the issue here. I've
I'll do the best to explain this, but please ask clarifying questions as needed:
Please allow me to preface this by saying I'm pretty much brand new to

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.