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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:32:50+00:00 2026-05-24T09:32:50+00:00

I have a interesting problem in Java, its a little wordy though so bear

  • 0

I have a interesting problem in Java, its a little wordy though so bear with me.

I decided to make a customizable Jpanel to act as a properties window, So instead manually designing each panel i wanted. I could just use the custom panel over and over with different parameters to “watch and edit” in the constructor, and it would do the rest (layout property listeners ect).

The problem i have is passing the primitive objects to and from the panel. When a value is changed in the panel, it should update the value that it corresponds to in the program. This would be easy with non-primitive objects, I would just pass the Object to the panel, then changing the object in the panel, would change the value of the object in the main program as well. With Primitive types such as Boolean and int, the actual value is passed to the Panel and not a reference and so changing these values in the panel wont affect the rest of the program.

the ideal solution would be to use a pointer. but these don’t exist in java. Another solution would be to encapsulate all the integer and Boolean types in a object, but i don’t really want to do this as it would mean a lot of rewriting of code in the main program.

There must be a way to do this but i cant think of it, any ideas?

Thanks in advance,

Chris.

  • 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-24T09:32:51+00:00Added an answer on May 24, 2026 at 9:32 am

    I would just pass the Object to the panel, then changing the object in
    the panel, would change the value of the object in the main program as
    well. With Primitive types such as Boolean and int, the actual value
    is passed to the Panel and not a reference and so changing these
    values in the panel wont affect the rest of the program.

    That’s wrong. In Java, everything is passed as copy of reference. It is just the case, that the reference of a calendar points to the object, as well as the copy of that reference, so changing the value the reference references, does what you want.

    But if you have a User, with User.name (String) and User.age (int), and modify them by an JTextField, for instance, you have the same problem, while String isn’t a primitive. Strings are immutable, so you could just change the String, a reference is pointing to, but since, what you pass, is a copy, the original object is not affected.

    // Invokes your Panel with a new copy of the string reference
    StringPropPanel ppun = new StringPropPanel (user.name); 
    // Invokes your Panel with a new copy of the int reference
    IntPropPanel ppua = new IntPropPanel (user.age); 
    // Invokes your Panel with a new copy of a User reference
    IntPropPanel ppup = new IntPropPanel (user.parent); 
    

    The last one would work – but raise the question, how to generate such a Panel from a User.

    PropPanel ppun = new PropPanel (user.name) {
        public void update () {
            user.setName (textfield.getText ());
        }
    }
    
    PropPanel ppun = new PropPanel (user.age) {
        public void update () {
            user.setAge (Integer.parseInt (textfield.getText ()));
        }
    }
    

    With an abstract update method, which is uniquely triggered, and can be overriden by anonymous ad-hoc implementations, you might be more successful.

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

Sidebar

Related Questions

I have interesting problem. I need to make tables in columns. Let me explain.
I have an interesting problem and would appreciate your thoughts for the best solution.
I have one interesting problem. I must parse mail body (regular expression), get some
I have some interesting problem for an hour.. In my flex project, all width
I have an interesting problem. The basis of the problem is that my last
I have an interesting problem when using partial page update in asp.net with scriptmanager
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have an interesting problem. I wrote the following perl script to recursively loop
I have an interesting problem here I've been trying to solve for the last
I have an interesting problem being reported to me from an android application I

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.