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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:30:39+00:00 2026-06-12T03:30:39+00:00

I want to make a GUI using Java in which a user can select

  • 0

I want to make a GUI using Java in which a user can select a bean, edit its fields, and then add an instance of the created bean to a queue. My question though is about accessing the fields. I have a class MyCompositeObject that inherits from MyParentObject. The MyParentObject is composed of multiple beans, each being composed of more beans. The class MyCompositeObject is also composed of beans. I want to find all accessible fields from MyCompositeObject.

Class MyParentObject
{
    MyObjectOne fieldOne;
    MyObjectTwo fieldTwo;
    String name;
  ...
 }

 Class MyCompositeObject extends MyParentObject
 {
    MyObjectThree fieldThree;
    Integer number;
   ...
 }

 Class MyObjectThree
 {
     boolean aBoolean;
     MyObjectFour fieldFour;
   ...
 }

I have been trying to use the BeanUtils api, but I’m getting stuck trying to get the fields of all the member beans. What I am imagining is a depth first search of all fields that could be accessed from an instance of MyCompositeObject. For example, this would include, but not be limited to, the fields: MyCompositeObject.fieldOne, MyCompositeObject.number, MyCompositeObject.fieldThree.aBoolean.

I realized when I tried:

Fields[] allFields = BeanUtils.getFields(myCompositeObject);

that I was in over my head. My research has so far not turned up any prebuilt methods that could do what I describe. Please let me know of any API methods that can do this or tell me how I can go about building my own. Thanks.

  • 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-12T03:30:41+00:00Added an answer on June 12, 2026 at 3:30 am

    It’s kind of a pain but you have to go in two dimensions

    yourBeanClass.getSuperclass(); (and recursively get all superclasses until Object)
    

    and then you can get the fields of each one

    eachClass.getDeclaredFields() NOT getFields so you can get all the private fields
    

    Once you have each field

    field.getType() which returns the Class of that field
    

    then of course, you need to go up that dudes superclass chain again to make sure you get ALL the fields of the class including the ones in the superclass

    Once you have that chain of classes for that field, you can then get it’s fields by repeating the above….yes, the jdk made this fun!!!! I wish to god they had a getAllDeclaredFields method so I didn’t have to go up the superclass heirarchy.

    IMPORTANT: you need to call field.setAccessible(true) so you can read and write to it when it is a private field by the way!!!

    Here is code that gets all the fields for a Class including the superclasses..

    private static List<Field> findAllFields(Class<?> metaClass) {
        List<Field[]> fields = new ArrayList<Field[]>();
        findFields(metaClass, fields);
    
        List<Field> allFields = new ArrayList<Field>();
        for(Field[] f : fields) {
            List<Field> asList = Arrays.asList(f);
            allFields.addAll(asList);
        }
        return allFields;
    }
    
    private static void findFields(Class metaClass2, List<Field[]> fields) {
        Class next = metaClass2;
        while(true) {
            Field[] f = next.getDeclaredFields();
            fields.add(f);
            next = next.getSuperclass();
            if(next.equals(Object.class))
                return;
        }
    }
    

    later,
    Dean

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

Sidebar

Related Questions

I want to make a nice simple gui using c++. which have drag and
I want make interactive application where user launches it and can do various task
Using Sql Express Management Studio 2008 GUI (not with coding), how can I make
I want to make a firefox plugin using XUL for making GUI. And I
I want to make a small GUI using Tk in Perl that will have
I am designing a GUI using Eclipse on Mac, and I want to make
I am using SwingWorkers to make my GUI responsive. But I can not understand
I want to make a program in python using pygtk, which would execute my
I want to make a GUI have a slider, this slider's value will be
I want to make some GUI mockup program for video player, so my idea

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.